html, body {
  margin: 0;
  height: 100%;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

body {
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

#topbar {
  flex: none;
  z-index: 1000;
  height: 48px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: #1f6feb;
  color: white;
  box-shadow: 0 1px 4px rgba(0,0,0,0.3);
}

#tourSelect {
  flex: 1;
  min-width: 0;
  height: 32px;
  border-radius: 6px;
  border: none;
  padding: 0 8px;
}

#status {
  flex: none;
  font-size: 12px;
  opacity: 0.9;
  white-space: nowrap;
}

@media (max-width: 480px) {
  #topbar {
    padding: 0 8px;
    gap: 6px;
  }
  #status {
    font-size: 11px;
  }
}

.icon-btn {
  flex: none;
  width: 30px;
  height: 30px;
  border: none;
  border-radius: 6px;
  background: rgba(255,255,255,0.15);
  color: white;
  font-size: 15px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

.icon-btn:hover {
  background: rgba(255,255,255,0.3);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f4f6fa;
}

/* L'overlay di login copre una pagina ancora vuota (nessun contesto da attenuare dietro);
   gli altri modali (es. cambio password) si aprono sopra la mappa gia' popolata, quindi
   usano uno sfondo semi-trasparente per lasciarla intravedere. */
.modal-overlay:not(#loginOverlay) {
  background: rgba(15, 23, 42, 0.45);
}

.modal-overlay[hidden] {
  display: none;
}

.modal-card {
  width: 100%;
  max-width: 300px;
  padding: 32px 28px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 4px 24px rgba(0,0,0,0.1);
  display: flex;
  flex-direction: column;
  gap: 14px;
  box-sizing: border-box;
}

.modal-card h1,
.modal-card h2 {
  margin: 0 0 8px 0;
  font-size: 20px;
  text-align: center;
  color: #1f6feb;
}

.modal-card label {
  display: flex;
  flex-direction: column;
  gap: 4px;
  font-size: 13px;
  color: #555;
}

.modal-card input {
  height: 38px;
  padding: 0 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  box-sizing: border-box;
}

.modal-card input:focus {
  outline: none;
  border-color: #1f6feb;
}

.modal-card button[type="submit"] {
  height: 40px;
  border: none;
  border-radius: 8px;
  background: #1f6feb;
  color: white;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  margin-top: 4px;
}

.modal-card button[type="submit"]:disabled {
  opacity: 0.6;
  cursor: default;
}

.modal-card .btn-secondary {
  height: 36px;
  border: 1px solid #ddd;
  border-radius: 8px;
  background: white;
  color: #555;
  font-size: 14px;
  cursor: pointer;
}

.form-error,
.form-success {
  margin: 0;
  font-size: 13px;
  text-align: center;
}

.form-error {
  color: #d64545;
}

.form-success {
  color: #2ecc71;
}

#loginError[hidden] {
  display: none;
}

#contentRow {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
  min-width: 0;
}

#mapWrap {
  flex: 1 1 auto;
  position: relative;
  min-height: 0;
  min-width: 0;
}

#map {
  position: absolute;
  inset: 0;
}

.speed-popup {
  font-size: 13px;
  line-height: 1.4;
}

.stop-popup-note {
  display: inline-block;
  margin-top: 4px;
  font-size: 12px;
  color: #666;
}

#streetsPanel {
  flex: none;
  display: flex;
  flex-direction: column;
  max-height: 45vh;
  overflow: hidden;
  background: white;
  border-top: 1px solid #ddd;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.08);
  transition: max-height 0.25s ease;
  z-index: 1000;
}

#streetsPanel.collapsed {
  max-height: 44px;
}

#streetsHeader {
  flex: none;
  height: 44px;
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: white;
  border: none;
  font-size: 14px;
  font-weight: 600;
  color: #222;
  cursor: pointer;
  font-family: inherit;
}

#streetsChevron {
  transition: transform 0.25s ease;
  color: #1f6feb;
}

#streetsPanel.collapsed #streetsChevron {
  transform: rotate(180deg);
}

#streetsBody {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

#streetsModeSwitch {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 8px 16px 0 16px;
}

#streetsModeSwitch .mode-btn {
  flex: 1;
  height: 32px;
  border: 1px solid #ddd;
  background: white;
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  color: #555;
  cursor: pointer;
}

#streetsModeSwitch .mode-btn.active {
  background: #1f6feb;
  border-color: #1f6feb;
  color: white;
  font-weight: 600;
}

/* Pulsante icona, stesso ingombro compatto di quelli nella barra in alto (.icon-btn), ma
   tema chiaro perche' vive sul pannello bianco invece che sulla topbar blu. */
.icon-mode-btn {
  flex: none;
  width: 32px;
  height: 32px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid #e74c3c;
  background: white;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1;
  color: #e74c3c;
  cursor: pointer;
}

.icon-mode-btn:hover {
  background: #fdeaea;
}

.icon-mode-btn.active {
  background: #e74c3c;
  color: white;
}

.icon-mode-btn:disabled {
  opacity: 0.6;
  cursor: default;
}

#streetsSearchWrap {
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-top: 1px solid #f0f0f0;
}

#streetsSearch {
  flex: 1 1 100px;
}

#autoZoomToggle {
  flex: none;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: #666;
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

#autoZoomToggle input {
  cursor: pointer;
}

#streetsSearch {
  min-width: 0;
  box-sizing: border-box;
  height: 34px;
  padding: 0 10px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
}

#streetsSearch:focus {
  outline: none;
  border-color: #1f6feb;
}

#streetsNavWrap {
  flex: none;
  display: flex;
  align-items: center;
  gap: 4px;
}

#streetsNavWrap button {
  flex: none;
  width: 28px;
  height: 28px;
  border: 1px solid #ddd;
  border-radius: 6px;
  background: white;
  color: #1f6feb;
  font-size: 11px;
  cursor: pointer;
}

#streetsNavWrap button:disabled {
  color: #ccc;
  cursor: default;
}

#navPosition {
  flex: none;
  font-size: 11px;
  color: #888;
  min-width: 44px;
  text-align: center;
}

#streetsList {
  list-style: none;
  margin: 0;
  padding: 0 0 8px 0;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
}

#streetsList li {
  padding: 10px 16px;
  border-top: 1px solid #f0f0f0;
  cursor: pointer;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}

#streetsList li:active,
#streetsList li.active {
  background: #eaf1fe;
}

#streetsList li[hidden],
#streetsList li.stop-group[hidden] {
  display: none;
}

#streetsList .street-count {
  font-size: 12px;
  color: #888;
  flex: none;
}

#streetsList .street-empty {
  color: #888;
  cursor: default;
  text-align: center;
}

/* Lista raccolta: una riga per via (aggregata), con indicatore di corrispondenza
   col percorso rilevato e note dei singoli civici espandibili */
#streetsList li.stop-group {
  display: block;
  padding: 0;
  cursor: default;
}

#streetsList li.stop-unmatched .stop-via-simple,
#streetsList li.stop-unmatched .street-count {
  color: #999;
}

.stop-group-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 16px;
}

.stop-group-row.stop-clickable {
  cursor: pointer;
}

.stop-group-row.stop-loading {
  opacity: 0.5;
  pointer-events: none;
}

.stop-group-row.stop-geocode-failed {
  background: #fdeaea;
}

.stop-geocode-error-msg {
  flex: none;
  font-size: 12px;
  font-weight: 600;
  color: #d64545;
}

.stop-dot {
  flex: none;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ccc;
}

.stop-matched .stop-dot {
  background: #2ecc71;
}

.stop-via-simple {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.stop-civ-badge {
  font-weight: 400;
  color: #1f6feb;
}

.stop-toggle {
  flex: none;
  width: 24px;
  height: 24px;
  border: none;
  background: transparent;
  color: #888;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  transition: transform 0.2s ease;
}

.stop-toggle.open {
  transform: rotate(180deg);
}

.stop-notes {
  list-style: none;
  margin: 0;
  padding: 0 16px 10px 34px;
}

.stop-notes li {
  font-size: 12px;
  color: #777;
  padding: 3px 0;
}

/* Tablet in orizzontale: spazio sufficiente per affiancare mappa e pannello vie invece di
   impilarli, con il pannello sempre visibile come colonna laterale fissa. Alla fine del
   foglio di stile cosi' vince per ordine sorgente sulle regole .collapsed viste sopra, a
   parita' di specificita' del selettore. */
@media (min-width: 700px) and (orientation: landscape) {
  #contentRow {
    flex-direction: row;
  }

  #streetsPanel,
  #streetsPanel.collapsed {
    flex: none;
    width: 360px;
    max-height: none;
    border-top: none;
    border-left: 1px solid #ddd;
    box-shadow: -2px 0 6px rgba(0,0,0,0.08);
  }

  #streetsHeader {
    cursor: default;
  }

  #streetsChevron {
    display: none;
  }
}

/* Pulsante "la mia posizione", flottante sull'angolo della mappa come i controlli di zoom. */
#locateBtn {
  position: absolute;
  right: 10px;
  bottom: 30px;
  z-index: 900;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: white;
  box-shadow: 0 1px 5px rgba(0,0,0,0.4);
  font-size: 20px;
  line-height: 1;
  color: #555;
  cursor: pointer;
}

#locateBtn:hover {
  color: #1f6feb;
}

#locateBtn.active {
  color: #1f6feb;
}

#locateBtn.locating {
  animation: locate-btn-pulse 1s ease-in-out infinite;
}

#locateMessage {
  position: absolute;
  left: 50%;
  bottom: 78px;
  transform: translateX(-50%);
  z-index: 900;
  max-width: 85%;
  padding: 8px 14px;
  background: rgba(20, 20, 20, 0.85);
  color: white;
  font-size: 13px;
  border-radius: 8px;
  text-align: center;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

#locateMessage[hidden] {
  display: none;
}

@keyframes locate-btn-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Marker della posizione del dispositivo: pallino blu con alone pulsante, stile "la mia
   posizione" delle app di mappe. */
.device-location-dot {
  position: relative;
  display: block;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: #1f6feb;
  border: 2px solid white;
  box-shadow: 0 0 2px rgba(0,0,0,0.4);
}

.device-location-dot::after {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  background: rgba(31, 111, 235, 0.3);
  animation: device-location-pulse 2s ease-out infinite;
}

@keyframes device-location-pulse {
  0% { transform: scale(0.6); opacity: 0.8; }
  100% { transform: scale(2.4); opacity: 0; }
}
