*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body,
#map {
  margin: 0;
  padding: 0;
  width: 100%;
  height: 100vh;
}

/* ── Pannello ── */
#panel {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 10;
  background: rgba(24, 26, 32, 0.93);
  color: #e8eaf0;
  padding: 10px 12px;
  border-radius: 10px;
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.45);
  font-family: "Segoe UI", system-ui, sans-serif;
  font-size: 15px;
  width: 370px;
  max-height: calc(100vh - 30px);
  overflow-y: auto;
  overflow-x: hidden;
}

/* ── Header: titolo + bottoni icon affiancati ── */
#panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
  cursor: pointer;
}

#panel-header h3 {
  margin: 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #7eb8f7;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

#panel-arrow {
  font-size: 10px;
  opacity: 0.7;
  transition: transform 0.2s;
  display: inline-block;
}

#panel-header .btn-icon-group {
  display: flex;
  gap: 4px;
  align-items: center;
  flex-shrink: 0;
}

#panel fieldset {
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 7px;
  margin: 0 0 8px;
  padding: 7px 9px 9px;
}

#panel legend {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #7eb8f7;
  padding: 0 4px;
}

/* ── Input ── */
#panel input[type="text"] {
  width: 100%;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 5px;
  color: #e8eaf0;
  padding: 5px 8px;
  font-size: 14px;
  margin-bottom: 5px;
  outline: none;
}

#panel input[type="text"]::placeholder {
  color: rgba(255, 255, 255, 0.35);
}

#panel input[type="text"]:focus {
  border-color: #7eb8f7;
  background: rgba(126, 184, 247, 0.08);
}

/* ── Riga cerca ── */
.row-search {
  display: flex;
  gap: 5px;
  margin-bottom: 6px;
}

.row-search input {
  flex: 1;
  margin-bottom: 0;
}

/* ── Riga partenza/dest ── */
.row-route {
  display: flex;
  gap: 5px;
  margin-bottom: 6px;
}

.row-route input {
  flex: 1;
  margin-bottom: 0;
}

/* ── Sezione Memoria ── */
.row-memoria {
  display: flex;
  gap: 5px;
  align-items: center;
}

#stopSearch {
  flex: 1;
  background: #2a2d3a;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 5px;
  color: #f0f2f8;
  padding: 4px 8px;
  font-size: 14px;
  outline: none;
}

#stopSearch::placeholder { color: #8890a8; }
#stopSearch:focus { border-color: #5c8df6; }

#stopSelect {
  flex: 1;
  background: #2a2d3a;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 5px;
  color: #f0f2f8;
  font-size: 14px;
  width: 100%;
}

#stopSelect option {
  background: #2a2d3a;
  color: #f0f2f8;
  padding: 2px 6px;
}

/* ── Mode select nel pannello tappe ── */
.mode-select {
  background: #1e2130;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 4px;
  color: #f0f2f8;
  font-size: 11px;
  cursor: pointer;
  padding: 1px 1px;
  width: 76px;
  flex-shrink: 0;
}

/* ── Badge segmento ── */
.seg-badge {
  font-size: 10px;
  background: #1a3560;
  color: #7eb8ff;
  border: 1px solid #2e5099;
  border-radius: 3px;
  padding: 1px 5px;
  flex-shrink: 0;
  font-weight: 700;
  letter-spacing: 0.3px;
}

/* ── Bottoni generici ── */
#panel button {
  border: none;
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 6px 10px;
  transition: filter 0.15s, opacity 0.15s;
  white-space: nowrap;
}

#panel button:hover {
  filter: brightness(1.15);
}

#panel button:active {
  opacity: 0.8;
}

.btn-icon {
  background: rgba(255, 255, 255, 0.1);
  color: #e8eaf0;
  padding: 5px 8px !important;
}

/* ── Griglia 2×2 bottoni azione ── */
.btn-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 5px;
  margin-top: 4px;
}

#calcCamperRoute {
  background: #1a6fba;
  color: #fff;
}

#addLeg {
  background: #2e7d32;
  color: #fff;
}

#saveToServer {
  background: #b35c00;
  color: #fff;
}

#clearCurrentRoute {
  background: #8b1a1a;
  color: #fff;
}

hr {
  border: none;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  margin: 7px 0;
}

/* ── Sezioni collassabili pannello ── */
.vrv-section {
  margin-bottom: 6px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  padding-bottom: 4px;
}
.vrv-section:last-child { border-bottom: none; }

.vrv-section__head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  padding: 5px 2px;
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #7eb8f7;
  text-transform: uppercase;
  user-select: none;
}
.vrv-section__head:hover { color: #a8d4ff; }

.vrv-section__arrow {
  font-size: 10px;
  opacity: 0.7;
  transition: transform 0.18s;
  display: inline-block;
}
.vrv-section__arrow.open { transform: rotate(0deg); }

.vrv-section__body {
  padding-top: 4px;
}

/* ── Riga km viaggio ── */
#km-viaggio {
  font-size: 14px;
  color: #a8d4ff;
  background: rgba(30, 58, 95, 0.5);
  border-radius: 6px;
  padding: 5px 9px;
  margin-bottom: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
#km-viaggio .km-label { opacity: 0.75; font-size: 12px; }

/* ── Bottoni zoom mappa ── */
#zoom-controls {
  position: absolute;
  bottom: 80px;
  right: 12px;
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
#zoom-controls button {
  width: 38px;
  height: 38px;
  background: rgba(24, 26, 32, 0.92);
  color: #e8eaf0;
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 8px;
  font-size: 22px;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  box-shadow: 0 2px 8px rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
}
#zoom-controls button:hover { background: rgba(50, 60, 80, 0.95); }
#zoom-controls button:active { opacity: 0.7; }
#zoom-level {
  background: rgba(24, 26, 32, 0.88);
  color: #a8d4ff;
  border: 1px solid rgba(255,255,255,0.15);
  border-radius: 6px;
  font-size: 12px;
  font-weight: 700;
  text-align: center;
  padding: 4px 0;
  width: 38px;
  font-family: "Segoe UI", system-ui, sans-serif;
  letter-spacing: 0.02em;
}

#calcSeg {
  background: #2a4a6a;
  color: #cce4ff;
}

/* Lista tappe — floating a destra del pannello */
.tappe-list {
  display: none;   /* chiusa di default, toggle con sezione Lista tappe */
  position: fixed;
  left: 392px;   /* 10px panel + 370px width + 12px gap */
  top: 10px;
  width: 380px;
  max-height: calc(100vh - 20px);
  overflow-y: auto;
  overflow-x: hidden;
  z-index: 200;
  border: 1px solid #3a3a4a;
  border-radius: 8px;
  background: rgba(22, 24, 32, 0.97);
  padding: 2px 0;
  box-shadow: 0 4px 24px rgba(0, 0, 0, 0.65);
}

.tappa-row {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 4px 7px;
  cursor: pointer;
  border-bottom: 1px solid #2a2a2a;
  font-size: 0.82rem;
  color: #ddd;
  transition: background 0.15s;
  min-width: 0;
}

.tappa-row:hover {
  background: #2a2a2a;
}

.tappa-row.selected {
  background: #1a3a5c;
  border-left: 3px solid #2196F3;
}

/* Tappe hidden: testo grigio, meno prominenti */
.tappa-row.tappa-hidden {
  color: #777;
  font-style: italic;
}

.tappa-icon {
  font-size: 0.75rem;
  flex-shrink: 0;
}

.tappa-nome {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.tappa-btn-rm {
  background: none;
  border: none;
  color: #888;
  cursor: pointer;
  font-size: 0.8rem;
  padding: 0 2px;
  line-height: 1;
  flex-shrink: 0;
  transition: color 0.15s;
}

.tappa-btn-rm:hover {
  color: #f44;
}

.tappa-row.selected-end {
  background: #1a5c2a;
  border-left: 3px solid #4CAF50;
}

/* Ancora verde (punto inserimento mappa) */
.tappa-ancora {
  background: rgba(139, 195, 74, 0.18) !important;
  border-left: 3px solid #8bc34a !important;
}

/* Destinazione blu */
.tappa-dest {
  background: rgba(33, 150, 243, 0.18) !important;
  border-left: 3px solid #2196f3 !important;
}

/* Range rosso (spinner elimina tratta) */
.tappa-range {
  background: rgba(211, 51, 51, 0.18) !important;
  border-left: 3px solid #d33 !important;
}

/* Numero riga */
.tappa-num {
  font-size: 0.7em;
  opacity: 0.5;
  min-width: 18px;
  text-align: right;
  flex-shrink: 0;
}
/* ── Help dropdown ───────────────────────────────────────────────── */
.vrv-help { position: relative; }

.vrv-help__menu {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: #1a2535;
  border: 1px solid #2a4a6a;
  border-radius: 8px;
  min-width: 150px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.6);
  z-index: 200;
  overflow: hidden;
}
.vrv-help__menu[aria-hidden="true"] { display: none; }
.vrv-help__menu a {
  display: block;
  padding: 10px 14px;
  color: #cce4ff;
  text-decoration: none;
  font-size: 0.88rem;
  white-space: nowrap;
}
.vrv-help__menu a:hover { background: #243650; }

/* ── Info modal ──────────────────────────────────────────────────── */
.vrv-modal {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  background: rgba(0,0,0,.6);
  z-index: 1000;
}
.vrv-modal.is-hidden { display: none; }
.vrv-modal__panel {
  width: min(560px, 92vw);
  background: #0f1520;
  color: #f0f0f0;
  border-radius: 14px;
  box-shadow: 0 20px 60px rgba(0,0,0,.6);
  overflow: hidden;
}
.vrv-modal__head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px;
  background: #151e2e;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.vrv-modal__head h3 { margin: 0; font-size: 1rem; font-weight: 600; }
.vrv-modal__close {
  appearance: none; border: 0; cursor: pointer;
  background: #2a3040; color: #fff;
  width: 32px; height: 32px; border-radius: 8px;
  font-size: 16px; line-height: 32px; text-align: center;
}
.vrv-modal__close:hover { background: #3a4050; }
.vrv-modal__body { padding: 16px 18px 20px; }
.vrv-modal__table { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }
.vrv-modal__table > div {
  display: grid; grid-template-columns: 140px 1fr; align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid rgba(255,255,255,.07);
}
.vrv-modal__table dt { opacity: .75; font-weight: 500; font-size: 0.88rem; }
.vrv-modal__table dd { margin: 0; font-size: 0.88rem; overflow-wrap: anywhere; }
.vrv-modal__table a { color: #90caf9; text-decoration: none; }
.vrv-modal__table a:hover { text-decoration: underline; }

/* ── Waypoint choice dialog ─────────────────────────────── */
.vrv-wp-panel { max-width: 420px; }
.vrv-wp-choice-btns { display: flex; gap: 10px; }
.vrv-wp-choice-btns button {
  flex: 1; padding: 10px 6px; font-size: 0.88rem;
  background: #1e3a5f; color: #cce4ff;
  border: 1px solid #2a4a6a; border-radius: 6px; cursor: pointer;
}
.vrv-wp-choice-btns button:hover { background: #2a4a6a; }
#vrv-wp-plan { background: #1a3d1a; border-color: #2d6b2d; color: #b8f0b8; }
#vrv-wp-plan:hover { background: #2d6b2d; }
#vrv-wp-plan-form input,
#vrv-wp-plan-form textarea {
  display: block; width: 100%; box-sizing: border-box;
  background: #0d1b2a; color: #cce4ff;
  border: 1px solid #2a4a6a; border-radius: 4px;
  padding: 6px 8px; margin-bottom: 8px; font-size: 0.85rem;
  font-family: inherit; resize: vertical;
}
#vrv-wp-plan-form input:focus,
#vrv-wp-plan-form textarea:focus { outline: none; border-color: #4caf50; }
#vrv-wp-save {
  width: 100%; padding: 8px; font-size: 0.88rem; font-family: inherit;
  background: #2d6b2d; color: #fff; border: none; border-radius: 6px; cursor: pointer;
}
#vrv-wp-save:hover { background: #3d8b3d; }

/* ── Form waypoint storico ──────────────────────────────── */
.vrv-wp-label {
  display: block; font-size: 0.78rem; color: #88aac8;
  margin-bottom: 3px; margin-top: 10px;
}
.vrv-wp-label:first-child { margin-top: 0; }
#vrv-wp-storico-form input[type="text"],
#vrv-wp-storico-form input[type="file"],
#vrv-wp-storico-form select {
  display: block; width: 100%; box-sizing: border-box;
  background: #0d1b2a; color: #cce4ff;
  border: 1px solid #2a4a6a; border-radius: 4px;
  padding: 6px 8px; font-size: 0.85rem; font-family: inherit;
}
#vrv-wp-storico-form input[type="text"]:focus,
#vrv-wp-storico-form select:focus { outline: none; border-color: #4090d0; }
#vrv-wp-storico-form input[type="file"] { padding: 4px 6px; cursor: pointer; color: #88aac8; }
.vrv-wp-after-list {
  max-height: 140px; overflow-y: auto;
  border: 1px solid #2a4a6a; border-radius: 4px;
  margin-top: 3px; background: #0a1520;
}
.vrv-wp-after-list:empty { display: none; }
.vrv-wp-result-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 10px; cursor: pointer; font-size: 0.84rem; color: #cce4ff;
  border-bottom: 1px solid #1a2a3a;
}
.vrv-wp-result-item:last-child { border-bottom: none; }
.vrv-wp-result-item:hover { background: #1a3050; }
.vrv-wp-result-order {
  font-size: 0.72rem; color: #5580a8; min-width: 32px; text-align: right;
}
.vrv-wp-after-selected {
  display: flex; align-items: center; justify-content: space-between;
  background: #0f2a10; border: 1px solid #2d6b2d;
  border-radius: 4px; padding: 5px 8px; font-size: 0.84rem;
  color: #b8f0b8; margin-top: 3px;
}
.vrv-wp-after-selected button {
  background: none; border: none; color: #5580a8;
  cursor: pointer; font-size: 0.85rem; padding: 0 4px;
}
.vrv-wp-after-selected button:hover { color: #ff6060; }
#vrv-wp-storico-save {
  display: block; width: 100%; margin-top: 14px;
  padding: 9px; font-size: 0.88rem; font-family: inherit;
  background: #1e3a5f; color: #cce4ff;
  border: 1px solid #2a4a6a; border-radius: 6px; cursor: pointer;
}
#vrv-wp-storico-save:hover { background: #2a4a6a; }

/* ── Risultati ricerca luoghi ───────────────────────────── */
#vrv-place-results {
  margin-top: 4px; max-height: 190px; overflow-y: auto;
  border: 1px solid #2a4a6a; border-radius: 6px; overflow-x: hidden;
}
.vrv-place-result {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 8px; font-size: 0.82rem; color: #cce4ff;
  border-bottom: 1px solid #1a3050; cursor: pointer;
}
.vrv-place-result:last-child { border-bottom: none; }
.vrv-place-result:hover { background: #1e3a5f; }
.vrv-place-result__name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vrv-place-result__add {
  flex-shrink: 0; background: #1a3d1a; color: #b8f0b8;
  border: 1px solid #2d6b2d; border-radius: 4px;
  padding: 1px 7px; cursor: pointer; font-size: 0.9rem; line-height: 1.4;
}
.vrv-place-result__add:hover { background: #2d6b2d; }

/* ── Profilo camper ─────────────────────────────────────── */
.vrv-camper-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vrv-camper-grid label { display: flex; flex-direction: column; font-size: 0.78rem; color: #aac8e8; gap: 3px; }
.vrv-camper-grid input { background: #0d1b2a; color: #cce4ff; border: 1px solid #2a4a6a; border-radius: 4px; padding: 5px 7px; font-size: 0.88rem; width: 100%; }
.vrv-camper-grid input:focus { outline: none; border-color: #4caf50; }
.vrv-avoid-opts { display: flex; flex-wrap: wrap; gap: 6px 14px; }
.vrv-avoid-opts label { font-size: 0.82rem; color: #aac8e8; display: flex; align-items: center; gap: 5px; cursor: pointer; }
.vrv-avoid-opts input[type=checkbox] { accent-color: #4caf50; cursor: pointer; width: 14px; height: 14px; }
