/* ==========================================================================
   Abruzzo Map - Mixed Routing & Hiking
   CSS dell'applicazione (stili base, plugin, routing e profilo altimetrico)
   ========================================================================== */

/* ------------------------------- Base layout ----------------------------- */

html,
body {
  height: 100%;
  padding: 0;
  margin: 0;
}

body {
  font-family: "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, sans-serif;
  overflow: hidden;
  background: #dfe6e9;
}

#map {
  width: 100%;
  height: 100vh;
  height: 100dvh;
}

#center_mark {
  position: absolute;
  top: calc(50% - 10px);
  left: calc(50% - 10px);
  z-index: 402;
  pointer-events: none;
  opacity: 0.6;
}

/* --------------------------- Ordine controlli ---------------------------- */
/* In alto a sinistra: Geolocalizzazione -> Traccia GPS -> Zoom -> Ricerca ->
   Info -> Quota -> Upload -> Autorouting -> Draw.                          */
/* In alto a destra: Vista 3D -> Schermo intero -> Bussola -> Mappe offline
   -> Layer.                                                                */

.leaflet-top.leaflet-left,
.leaflet-top.leaflet-right {
  display: flex !important;
  flex-direction: column !important;
}

/* I controlli non devono allargarsi fino alla larghezza del figlio piu'
   largo (es. il selettore layer aperto): altrimenti i pulsanti sembrano
   traslare e il contenitore risulta piu' largo del pulsante. */
.leaflet-top.leaflet-left {
  align-items: flex-start;
}

.leaflet-top.leaflet-right {
  align-items: flex-end;
}

.leaflet-control-locate {
  order: 1;
}

.leaflet-control-zoom {
  order: 10;
}

.leaflet-control-geocoder,
.leaflet-control-search,
.leaflet-control[class*="search"],
.leaflet-control[class*="geocoder"] {
  order: 30;
}

/* --------------------------- Legenda dinamica ---------------------------- */

.info.legend {
  display: block;
  padding: 0;
  color: #333;
  font-size: 13px;
  line-height: 1.4;
  background: rgba(255, 255, 255, 0.88);
  border-radius: 8px;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.15);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.legend-header {
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  padding: 6px 6px 6px 12px;
  border-bottom: 1px solid rgba(0, 0, 0, 0.1);
}

.legend-title {
  font-size: 12px;
  font-weight: 700;
  color: #2c3e50;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.legend-toggle-btn {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  padding: 0;
  color: #2c3e50;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  background: rgba(0, 0, 0, 0.06);
  border: 0;
  border-radius: 5px;
  transition: background-color 0.15s ease;
}

.legend-toggle-btn:hover,
.legend-toggle-btn:focus {
  background: rgba(0, 0, 0, 0.14);
  outline: none;
}

/* L'icona del pulsante non deve ereditare gli stili dei campioni colore */
.legend-toggle-btn i {
  float: none;
  width: auto;
  height: auto;
  margin: 0;
  background: none;
  border-radius: 0;
  opacity: 1;
}

.legend-content {
  padding: 10px 14px;
}

.legend-content::after {
  display: block;
  clear: both;
  content: "";
}

/* Legenda iconizzata: resta visibile solo il pulsante di ripristino */
.info.legend.legend--collapsed .legend-title,
.info.legend.legend--collapsed .legend-content {
  display: none;
}

.info.legend.legend--collapsed {
  padding: 4px;
}

.info.legend.legend--collapsed .legend-header {
  padding: 0;
  border-bottom: 0;
}

.legend-empty {
  display: none;
  font-size: 12px;
  font-style: italic;
  color: #666;
}

.legend-section {
  display: none;
  margin-bottom: 8px;
}

.legend-section:last-child {
  margin-bottom: 0;
}

.info.legend i,
.legend i {
  display: inline-block;
  vertical-align: middle;
  width: 18px;
  height: 18px;
  margin-right: 8px;
  opacity: 0.85;
  border-radius: 3px;
  border: 1px solid rgba(0, 0, 0, 0.25);
}

.legend-badge {
  display: inline-block;
  padding: 1px 5px;
  margin-left: 4px;
  border-radius: 8px;
  background: #fff3cd;
  border: 1px solid #e0c068;
  color: #7a5a00;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  vertical-align: middle;
}

.legend-note {
  clear: both;
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.35;
  font-style: italic;
  color: #555;
}

.legend-note:empty {
  display: none;
}

/* ------------------- Pannello routing compatto (135px) ------------------- */

.leaflet-routing-container {
  width: 135px !important;
  min-width: 135px !important;
  max-width: 135px !important;
  padding: 5px !important;
  background: rgba(255, 255, 255, 0.94) !important;
  border-radius: 8px !important;
  box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2) !important;
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

/* Nasconde la descrizione testuale dell'itinerario e il tasto "+" */
.leaflet-routing-alt,
.leaflet-routing-add-waypoint {
  display: none !important;
}

.leaflet-routing-geocoders {
  margin-bottom: 0 !important;
}

.leaflet-routing-geocoder {
  display: flex !important;
  align-items: center !important;
  margin: 3px 0 !important;
}

.leaflet-routing-geocoder input {
  width: calc(100% - 18px) !important;
  height: 20px !important;
  padding: 1px 4px !important;
  font-size: 10px !important;
  line-height: 20px !important;
  background: #fff !important;
  border: 1px solid #ccc !important;
  border-radius: 4px !important;
}

.leaflet-routing-remove-waypoint {
  width: 16px !important;
  height: 20px !important;
  margin-left: 2px !important;
  line-height: 20px !important;
  opacity: 0.7;
}

.leaflet-routing-remove-waypoint:hover {
  opacity: 1;
}

/* --------------------- Selettore mezzo di trasporto ---------------------- */

.routing-mode-selector-inline {
  padding: 0 0 5px;
  margin-bottom: 5px;
  border-bottom: 1px solid #e0e0e0;
}

.mode-btn {
  flex: 1;
  box-sizing: border-box;
  padding: 4px 0;
  color: #333;
  font-size: 16px;
  line-height: 1.2;
  text-align: center;
  cursor: pointer;
  background: #f8f9fa;
  border: 1px solid #ced4da;
  border-radius: 6px;
  transition: all 0.2s ease;
}

.mode-btn:hover {
  background: #e9ecef;
}

.mode-btn.active {
  color: #fff;
  background: #007bff;
  border-color: #007bff;
}

/* --------------- Pulsante "END" del routing (rosso, leggibile) ----------- */

.leaflet-bar button.routing-terminate-btn,
.leaflet-routing-container button.routing-terminate-btn,
.routing-terminate-btn {
  display: block !important;
  box-sizing: border-box !important;
  width: 100% !important;
  height: auto !important;
  min-height: 28px !important;
  padding: 6px 4px !important;
  margin-top: 6px !important;
  overflow: visible !important;
  font-size: 11px !important;
  font-weight: bold !important;
  line-height: 1.3 !important;
  color: #fff !important;
  text-align: center !important;
  text-transform: uppercase !important;
  white-space: normal !important;
  cursor: pointer !important;
  background-color: #dc3545 !important;
  border: 1px solid #b02a37 !important;
  border-radius: 4px !important;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.2) !important;
}

.leaflet-bar button.routing-terminate-btn:hover,
.leaflet-routing-container button.routing-terminate-btn:hover,
.routing-terminate-btn:hover {
  color: #fff !important;
  background-color: #c82333 !important;
}

/* ---------------------- Pannello profilo altimetrico --------------------- */

#elevation-panel {
  position: absolute;
  bottom: 15px;
  bottom: max(15px, env(safe-area-inset-bottom));
  left: 50%;
  z-index: 1000;
  display: none;
  width: 92%;
  max-width: 680px;
  padding: 10px 14px;
  font-family: sans-serif;
  background: rgba(255, 255, 255, 0.94);
  border-radius: 10px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.25);
  transform: translateX(-50%);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}

.elevation-header {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
  color: #444;
  font-size: 11px;
  font-weight: 600;
}

.elevation-header-left {
  display: flex;
  gap: 8px;
  align-items: center;
}

.elevation-controls {
  display: flex;
  gap: 4px;
  align-items: center;
}

.elevation-controls input {
  width: 45px;
  padding: 2px 4px;
  font-size: 11px;
  text-align: center;
  border: 1px solid #ccc;
  border-radius: 4px;
}

#elevation-close-btn {
  padding: 0 4px;
  font-size: 20px;
  font-weight: bold;
  line-height: 1;
  color: #dc3545;
  cursor: pointer;
  background: none;
  border: none;
}

#elevation-close-btn:hover {
  color: #000;
}

.chart-container {
  position: relative;
  width: 100%;
  height: 110px;
}

/* -------------------------- Icone personalizzate ------------------------ */

.custom-water-icon {
  background: none;
  border: none;
}

/* ----------------------- Avviso iniziale non bloccante ------------------- */

.app-notice {
  position: fixed;
  left: 50%;
  bottom: max(32px, env(safe-area-inset-bottom));
  z-index: 1200;
  display: flex;
  gap: 10px;
  align-items: flex-start;
  width: min(620px, calc(100vw - 32px));
  padding: 10px 12px;
  color: #333;
  font-size: 14px;
  line-height: 1.35;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid rgba(0, 0, 0, 0.15);
  border-radius: 8px;
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.28);
  transform: translateX(-50%);
}

.app-notice[hidden] {
  display: none;
}

.app-notice__text {
  flex: 1;
}

.app-notice__close {
  flex: 0 0 auto;
  padding: 0 4px;
  font-size: 22px;
  line-height: 1;
  color: #555;
  cursor: pointer;
  background: transparent;
  border: 0;
}

.app-notice__close:hover,
.app-notice__close:focus {
  color: #000;
}

/* ------------------------------ Varie ----------------------------------- */

.leaflet-popup-tip {
  border: 0;
}

.leaflet-fade-anim .leaflet-tile,
.leaflet-zoom-anim .leaflet-zoom-animated {
  will-change: auto !important;
}

.noscript {
  position: absolute;
  top: 50%;
  left: 50%;
  z-index: 2000;
  padding: 16px;
  margin: 0;
  background: #fff;
  transform: translate(-50%, -50%);
}

/* ------------------------------ Responsive ------------------------------ */

@media (max-width: 768px) {
  #elevation-panel {
    bottom: 5px;
    width: 95%;
    padding: 8px;
  }

  .chart-container {
    height: 90px;
  }

  .leaflet-control-layers {
    max-width: min(260px, calc(100vw - 80px));
    max-height: 58vh;
    overflow-y: auto;
  }

  .leaflet-touch .leaflet-bar a {
    width: 38px;
    height: 38px;
    line-height: 38px;
  }

  .leaflet-control-attribution {
    max-width: 70vw;
    overflow: hidden;
    font-size: 10px;
    white-space: nowrap;
    text-overflow: ellipsis;
  }
}

@media (max-height: 480px) {
  #elevation-panel {
    max-height: 42vh;
    overflow-y: auto;
  }

  .chart-container {
    height: 70px;
  }

  #center_mark {
    display: none;
  }
}
