/* ── Variabili ──────────────────────────────────────────────────────────────── */
:root {
  --green-dark:  #2D6A4F;
  --green-mid:   #52B788;
  --green-light: #D8F3DC;
  --text:        #1a1a2e;
  --muted:       #6c757d;
  --radius:      14px;
}

/* ── Reset & layout base ────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  overflow: hidden;
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
}

#app { position: relative; height: 100%; }

/* ── Mappa ──────────────────────────────────────────────────────────────────── */
#map {
  position: absolute;
  inset: 0;
  z-index: 1;
}

/* ── Barra GPS ──────────────────────────────────────────────────────────────── */
#gps-bar {
  position: fixed;
  top: 12px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 900;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  border-radius: 20px;
  padding: 6px 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  white-space: nowrap;
  pointer-events: none;
}
#gps-bar i { font-size: 14px; }

/* ── Overlay (chiude il panel) ──────────────────────────────────────────────── */
#panel-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.25);
  z-index: 999;
}
#panel-overlay.visible { display: block; }

/* ── Bottom panel ───────────────────────────────────────────────────────────── */
#tree-panel {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 1000;
  background: #fff;
  border-radius: 20px 20px 0 0;
  box-shadow: 0 -6px 24px rgba(0,0,0,0.15);
  transform: translateY(100%);
  transition: transform 0.35s cubic-bezier(0.32, 0.72, 0, 1);
  max-height: 88vh;
  overflow-y: auto;
  overscroll-behavior: contain;
}
#tree-panel.open { transform: translateY(0); }

/* Handle drag */
.panel-handle {
  width: 44px;
  height: 4px;
  background: #ddd;
  border-radius: 2px;
  margin: 12px auto 0;
  cursor: pointer;
  flex-shrink: 0;
}

/* ── Contenuto panel: preview ───────────────────────────────────────────────── */
.tree-img {
  width: 100%;
  height: 210px;
  object-fit: cover;
  display: block;
}
.tree-img-placeholder {
  width: 100%;
  height: 160px;
  background: var(--green-light);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 56px;
}

/* ── Gallery foto ───────────────────────────────────────────────────────────── */
#panel-gallery {
  position: relative;
}

.gallery-track {
  display: flex;
  height: 220px;
  overflow-x: auto;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
  -ms-overflow-style: none;
}
.gallery-track::-webkit-scrollbar { display: none; }

.gallery-slide {
  flex: 0 0 100%;
  scroll-snap-align: start;
}
.gallery-slide img {
  width: 100%;
  height: 220px;
  object-fit: cover;
  display: block;
}

.gallery-counter {
  position: absolute;
  bottom: 10px;
  right: 12px;
  background: rgba(0, 0, 0, 0.52);
  color: #fff;
  border-radius: 20px;
  padding: 3px 10px;
  font-size: 12px;
  font-weight: 600;
  pointer-events: none;
}

.panel-meta {
  padding: 16px 20px 4px;
}
.panel-title {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--text);
  line-height: 1.2;
}
.panel-slug {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 2px;
}

/* ── Badge prossimità ───────────────────────────────────────────────────────── */
.proximity-badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  margin: 12px 20px 0;
}
.proximity-badge.near { background: var(--green-light); color: var(--green-dark); }
.proximity-badge.far  { background: #fff3cd; color: #856404; }
.proximity-badge.wait { background: #e9ecef; color: var(--muted); }

/* ── Pulsante sblocco ───────────────────────────────────────────────────────── */
.btn-unlock {
  display: block;
  width: calc(100% - 40px);
  margin: 14px 20px 24px;
  padding: 15px;
  background: var(--green-dark);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}
.btn-unlock:active   { transform: scale(0.98); }
.btn-unlock:hover:not(:disabled) { background: var(--green-mid); }
.btn-unlock:disabled { background: #ccc; cursor: not-allowed; }

/* ── Tab contenuto sbloccato ────────────────────────────────────────────────── */
.content-tabs {
  display: flex;
  border-bottom: 2px solid var(--green-light);
  padding: 0 20px;
  overflow-x: auto;
  scrollbar-width: none;
}
.content-tabs::-webkit-scrollbar { display: none; }

.tab-btn {
  flex-shrink: 0;
  padding: 10px 14px;
  border: none;
  background: none;
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: color 0.2s, border-color 0.2s;
}
.tab-btn.active {
  color: var(--green-dark);
  font-weight: 600;
  border-bottom-color: var(--green-dark);
}

.tab-pane {
  padding: 18px 20px 36px;
  font-size: 0.95rem;
  line-height: 1.75;
  color: var(--text);
}

/* ── Overlay permesso GPS ───────────────────────────────────────────────────── */
#geo-overlay {
  position: fixed;
  inset: 0;
  z-index: 1100;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#geo-overlay[hidden] { display: none; }

#geo-card {
  background: #fff;
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}
.geo-card-icon  { font-size: 3rem; margin-bottom: 12px; }
.geo-card-title { font-size: 1.25rem; font-weight: 700; color: var(--text); margin-bottom: 10px; }
.geo-card-desc  { font-size: 0.92rem; color: var(--muted); line-height: 1.65; margin-bottom: 24px; }

.btn-geo-primary {
  display: block;
  width: 100%;
  padding: 14px;
  background: var(--green-dark);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  margin-bottom: 12px;
  transition: background 0.2s;
}
.btn-geo-primary:hover { background: var(--green-mid); }

.btn-geo-skip {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 0.85rem;
  cursor: pointer;
  text-decoration: underline;
}

/* ── Marker SVG (iniettato da Leaflet) ──────────────────────────────────────── */
.tree-marker { cursor: pointer; }

/* ── Loading state albero già sbloccato ─────────────────────────────────────── */
.unlock-loading {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 24px;
  color: var(--muted);
  font-size: 0.9rem;
}
.spinner-dark {
  flex-shrink: 0;
  width: 18px;
  height: 18px;
  border: 2px solid rgba(0, 0, 0, 0.1);
  border-top-color: var(--green-dark);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

/* ── Spinner caricamento ────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Pulsante centra posizione ──────────────────────────────────────────────── */
#btn-locate {
  position: fixed;
  bottom: 104px; /* sopra i controlli zoom Leaflet (~80px) */
  right: 10px;
  z-index: 900;
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  border: none;
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.2);
  font-size: 18px;
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s, color 0.2s;
}
#btn-locate:hover  { background: var(--green-light); color: var(--green-dark); }
#btn-locate:active { transform: scale(0.93); }

/* ── User badge ─────────────────────────────────────────────────────────────── */
#user-badge {
  position: fixed;
  top: 12px;
  left: 12px;
  z-index: 900;
  background: rgba(255, 255, 255, 0.95);
  backdrop-filter: blur(6px);
  border: none;
  border-radius: 20px;
  padding: 6px 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text);
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  cursor: pointer;
  transition: background 0.2s;
  white-space: nowrap;
}
#user-badge:hover { background: rgba(240, 240, 240, 0.98); }
#user-badge:not(.logged-in) { gap: 0; }
#user-badge.logged-in { background: var(--green-light); color: var(--green-dark); }
#user-badge-initials { font-weight: 700; }
#user-badge-points { font-size: 11px; opacity: 0.8; }

/* ── Auth modal ─────────────────────────────────────────────────────────────── */
#auth-modal {
  position: fixed;
  inset: 0;
  z-index: 1200;
  background: rgba(0, 0, 0, 0.6);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
#auth-modal[hidden] { display: none; }

#auth-modal-card {
  background: #fff;
  border-radius: 20px;
  padding: 32px 28px;
  max-width: 360px;
  width: 100%;
  position: relative;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
  text-align: center;
}
#auth-modal-card h2 {
  font-size: 1.3rem;
  font-weight: 700;
  color: var(--green-dark);
  margin-bottom: 20px;
}
.auth-logo { font-size: 2.5rem; margin-bottom: 6px; }

#auth-modal-close {
  position: absolute;
  top: 14px;
  right: 16px;
  background: none;
  border: none;
  font-size: 1.4rem;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
#auth-modal-close:hover { color: var(--text); }

/* Tabs */
.auth-tabs {
  display: flex;
  gap: 4px;
  background: #f1f3f5;
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 20px;
}
.auth-tab {
  flex: 1;
  border: none;
  background: none;
  border-radius: 8px;
  padding: 8px;
  font-size: 0.88rem;
  color: var(--muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.auth-tab.active {
  background: #fff;
  color: var(--green-dark);
  font-weight: 600;
  box-shadow: 0 1px 4px rgba(0,0,0,0.1);
}

/* Form */
.auth-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
  text-align: left;
}
.auth-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1.5px solid #dee2e6;
  border-radius: 10px;
  font-size: 0.95rem;
  outline: none;
  transition: border-color 0.2s;
}
.auth-form input:focus { border-color: var(--green-mid); }

.auth-form button[type=submit] {
  width: 100%;
  padding: 13px;
  background: var(--green-dark);
  color: #fff;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}
.auth-form button[type=submit]:hover:not(:disabled) { background: var(--green-mid); }
.auth-form button[type=submit]:disabled { background: #ccc; cursor: not-allowed; }

.auth-error {
  color: #dc3545;
  font-size: 0.83rem;
  min-height: 18px;
}

/* ── Lang selector ──────────────────────────────────────────────────────────── */
.lang-selector {
  display: flex;
  gap: 6px;
  padding: 10px 20px 4px;
  overflow-x: auto;
  scrollbar-width: none;
}
.lang-selector::-webkit-scrollbar { display: none; }

.lang-btn {
  flex-shrink: 0;
  padding: 5px 10px;
  border: 1.5px solid #dee2e6;
  border-radius: 20px;
  background: none;
  font-size: 0.8rem;
  color: var(--muted);
  cursor: pointer;
  transition: border-color 0.2s, color 0.2s, background 0.2s;
}
.lang-btn.active {
  border-color: var(--green-dark);
  color: var(--green-dark);
  background: var(--green-light);
  font-weight: 600;
}

/* ── Lang fallback notice ───────────────────────────────────────────────────── */
.lang-fallback-notice {
  margin: 4px 20px 0;
  padding: 6px 10px;
  background: #fff3cd;
  color: #856404;
  border-radius: 8px;
  font-size: 0.8rem;
}

/* ── Toast container ────────────────────────────────────────────────────────── */
#toast-container {
  position: fixed;
  bottom: 90px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 1100;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: rgba(45, 106, 79, 0.95);
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: 0 4px 16px rgba(0,0,0,0.25);
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.3s, transform 0.3s;
  white-space: nowrap;
}
.toast.show {
  opacity: 1;
  transform: translateY(0);
}
