:root {
  --ui-bg: #ffffff;
  --ui-muted: #f4f7f8;
  --ui-border: #d8e0e3;
  --ui-text: #253238;
  --ui-text-muted: #5c6b72;
  --accent-color: #1a627b;
  --accent-color-hover: #124b5f;
  --ui-font: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  --serif-font: 'Cardo', serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--ui-font);
  color: var(--ui-text);
  background: var(--ui-bg);
}

#mappa-wrapper {
  max-width: 1300px;
  margin: 0 auto;
  padding: 1.5rem;
}

#mappa-header h1 {
  font-family: var(--serif-font);
  font-size: 2rem;
  margin: 0 0 0.3rem 0;
  color: var(--ui-text);
}
#mappa-header p {
  margin: 0 0 1.2rem 0;
  color: var(--ui-text-muted);
  font-size: 0.95rem;
}

#mappa-layout {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 1.2rem;
}

#map {
  height: 78vh;
  min-height: 480px;
  border: 1px solid var(--ui-border);
  border-radius: 8px;
}

#mappa-sidebar {
  height: 78vh;
  min-height: 480px;
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  background: var(--ui-muted);
  overflow-y: auto;
  padding: 1rem;
}

#mappa-sidebar-empty {
  color: var(--ui-text-muted);
  font-size: 0.9rem;
  padding: 1rem;
  text-align: center;
}

.sidebar-place-title {
  font-family: var(--serif-font);
  font-size: 1.25rem;
  font-weight: 700;
  margin: 0 0 0.9rem 0;
  padding-bottom: 0.6rem;
  border-bottom: 2px solid var(--accent-color);
  color: var(--ui-text);
}

.noterella-item {
  display: block;
  background: var(--ui-bg);
  border: 1px solid var(--ui-border);
  border-left: 4px solid var(--accent-color);
  border-radius: 6px;
  padding: 0.7rem 0.9rem;
  margin-bottom: 0.6rem;
  text-decoration: none;
  color: var(--ui-text);
  font-family: var(--serif-font);
  font-size: 0.95rem;
  transition: background 0.15s, transform 0.1s;
}
.noterella-item:hover {
  background: var(--ui-muted);
  transform: translateX(2px);
}
.noterella-item .transit-tag {
  display: inline-block;
  font-family: var(--ui-font);
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--accent-color);
  background: #e8f1f4;
  border-radius: 3px;
  padding: 1px 6px;
  margin-left: 6px;
  vertical-align: middle;
}

/* Marker numerati (ordine cronologico) */
.tappa-marker {
  background: var(--accent-color);
  color: #fff;
  border-radius: 50%;
  width: 26px; height: 26px;
  display: flex; align-items: center; justify-content: center;
  font-family: var(--ui-font);
  font-weight: 700;
  font-size: 0.72rem;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}
.tappa-marker.active {
  background: var(--accent-color-hover);
  transform: scale(1.15);
}

.leaflet-popup-content-wrapper {
  font-family: var(--ui-font);
  border-radius: 6px;
}
.leaflet-popup-content b {
  font-family: var(--serif-font);
}

/* Testo della noterella mostrato direttamente nella sidebar */
.mappa-back {
  display: inline-block;
  font-size: 0.8rem;
  color: var(--accent-color);
  text-decoration: none;
  margin-bottom: 0.8rem;
}
.mappa-back:hover { text-decoration: underline; }

.mappa-noterella-body {
  font-family: var(--serif-font);
  font-size: 1.02rem;
  line-height: 1.75;
  color: var(--ui-text);
}
.mappa-noterella-body .mappa-p {
  margin: 0 0 0.9rem 0;
  text-indent: 1.6em;
  text-align: justify;
}
.mappa-noterella-body .mappa-p:first-child,
.mappa-noterella-body .mappa-asterism + .mappa-p { text-indent: 0; }
.mappa-noterella-body .mappa-asterism {
  display: block;
  text-align: center;
  letter-spacing: 0.3em;
  margin: 0.8rem 0;
  color: var(--ui-text-muted);
}

.mappa-open-full {
  display: inline-block;
  margin-top: 1rem;
  padding: 0.5rem 0.9rem;
  background: var(--accent-color);
  color: #fff;
  text-decoration: none;
  border-radius: 6px;
  font-size: 0.85rem;
  font-weight: 600;
}
.mappa-open-full:hover { background: var(--accent-color-hover); }

@media (max-width: 860px) {
  #mappa-layout { grid-template-columns: 1fr; }
  #map, #mappa-sidebar { height: 55vh; min-height: 380px; }
}


/* ============================================================
   MARKER (numero + tipo via colore + icona SVG) 
   ============================================================ */
.tappa-marker {
  position: relative;
  background: var(--accent-color); color:#fff; border-radius:50%;
  width:28px; height:28px; margin:2px; display:flex; align-items:center; justify-content:center;
  font-family: var(--ui-font); font-weight:700; font-size:0.75rem;
  border:2px solid #fff; box-shadow:0 1px 4px rgba(0,0,0,.35);
  transition: transform .12s, opacity .2s, box-shadow .2s;
}
.tappa-marker.t-battle { background:#a83232; }
.tappa-marker.t-naval  { background:#2c6e8f; }
.tappa-marker.active   { transform: scale(1.2); box-shadow:0 2px 8px rgba(0,0,0,.5); z-index:1000; }
.tappa-marker .tappa-badge {
  position:absolute; bottom:-5px; right:-6px;
  background:#fff; color:#333; border-radius:50%; width:16px; height:16px;
  display:flex; align-items:center; justify-content:center; box-shadow:0 1px 2px rgba(0,0,0,.35);
}
.tappa-marker.t-battle .tappa-badge { color:#a83232; }
.tappa-marker.t-naval  .tappa-badge { color:#2c6e8f; }
.tappa-marker.dimmed { opacity:0.25; }
.tappa-marker.theme-hit { transform:scale(1.12); }
.narr-marker { width:16px; height:16px; border-radius:50%; border:2px solid #fff; box-shadow:0 1px 3px rgba(0,0,0,.4); }

/* ============================================================
   LEGENDA-CONTROLLO
   ============================================================ */
.map-legend {
  background: rgba(255,255,255,0.97);
  border: 1px solid var(--ui-border);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(0,0,0,0.15);
  font-family: var(--ui-font);
  width: 236px; max-width: 72vw;
  overflow: hidden;
}
.lg-head {
  display:flex; align-items:center; justify-content:space-between;
  background: var(--accent-color); color:#fff;
  padding: 7px 12px; font-weight:700; font-size:0.85rem;
}
.lg-collapse { background:none; border:none; color:#fff; font-size:1.1rem; line-height:1; cursor:pointer; padding:0 4px; }
.lg-body { padding: 8px 12px 10px; max-height: 62vh; overflow-y:auto; }
.map-legend.collapsed .lg-body { display:none; }

.lg-sec { font-size:0.7rem; font-weight:700; text-transform:uppercase; letter-spacing:0.04em;
  color:var(--ui-text-muted); margin:10px 0 5px; }
.lg-sec:first-child { margin-top:2px; }
.lg-sub { text-transform:none; font-weight:400; letter-spacing:0; }

.lg-row { display:flex; align-items:center; gap:8px; padding:3px 0; font-size:0.82rem; color:var(--ui-text); }
.lg-toggle { cursor:pointer; border-radius:4px; }
.lg-toggle:hover { background:var(--ui-muted); }
.lg-toggle input { margin:0; }

.lg-swatch { flex:0 0 auto; display:inline-flex; align-items:center; justify-content:center; }
.lg-circle { width:18px; height:18px; border-radius:50%; background:var(--accent-color); color:#fff; border:2px solid #fff; box-shadow:0 1px 2px rgba(0,0,0,.3); }
.lg-circle.lg-battle { background:#a83232; }
.lg-circle.lg-naval  { background:#2c6e8f; }
.lg-line { width:22px; height:0; border-top:3px solid var(--accent-color); }
.lg-line.dash { border-top-style:dashed; }
.lg-theme { width:14px; height:14px; border-radius:3px; background:#ffcf33; border:1px solid #e0b420; }
.lg-txt { flex:1; }
.lg-count { font-size:0.72rem; color:var(--ui-text-muted); background:var(--ui-muted); border-radius:10px; padding:0 6px; }

.lg-foot { display:flex; align-items:center; justify-content:space-between; margin-top:8px; padding-top:6px; border-top:1px solid var(--ui-border); font-size:0.75rem; color:var(--ui-text-muted); }
.lg-reset { background:none; border:1px solid var(--ui-border); border-radius:4px; padding:2px 8px; font-size:0.72rem; cursor:pointer; color:var(--ui-text); }
.lg-reset:hover { background:var(--ui-muted); }

@media (max-width: 860px) {
  .map-legend { width:200px; }
  .lg-body { max-height:46vh; }
}

/* ============================================================
   NUOVE FUNZIONI: riepilogo, toolbar, timeline, frecce, start/end,
   cluster, orizzonte, versi, stampa
   ============================================================ */
#mappa-summary { font-size:0.9rem; color:var(--ui-text); margin:0 0 0.5rem; }
#mappa-summary b { color:var(--accent-color); }
.mappa-intro { margin:0 0 1rem; color:var(--ui-text-muted); font-size:0.92rem; }

#mappa-toolbar { display:flex; gap:0.6rem; margin-bottom:0.7rem; flex-wrap:wrap; }
#mappa-search { flex:1; min-width:200px; padding:0.5rem 0.8rem; border:1px solid var(--ui-border); border-radius:6px; font-family:var(--ui-font); font-size:0.9rem; }
#mappa-search:focus { outline:none; border-color:var(--accent-color); }
#mappa-search.nohit { border-color:#c0392b; background:#fdecea; }
#mappa-print { padding:0.5rem 0.9rem; border:1px solid var(--ui-border); border-radius:6px; background:var(--ui-muted); cursor:pointer; font-family:var(--ui-font); font-size:0.9rem; }
#mappa-print:hover { background:var(--btn-bg-hover); }

#mappa-timeline-wrap { display:flex; align-items:center; gap:0.7rem; margin-bottom:1rem; font-size:0.85rem; color:var(--ui-text-muted); }
#mappa-timeline-wrap label { font-weight:600; white-space:nowrap; }
#mappa-timeline { flex:1; accent-color:var(--accent-color); }
#mappa-timeline-label { font-weight:700; color:var(--accent-color); white-space:nowrap; min-width:90px; }

/* Frecce di direzione sulla rotta */
.route-arrow { color:#1a627b; font-size:14px; line-height:16px; text-align:center; opacity:0.75; }

/* Marker partenza/arrivo */
.tappa-marker.t-start { background:#27ae60; }
.tappa-marker.t-end   { background:#c0392b; }

/* Cluster (ventaglio) */
.cluster-marker {
  width:32px; height:32px; border-radius:10px; /* quadrato smussato, non un cerchio: si distingue subito da una tappa */
  background:#5a7a8a; color:#fff; display:flex; align-items:center; justify-content:center;
  font-family:var(--ui-font); font-weight:700; font-size:0.85rem;
  border:2px dashed #fff; box-shadow:0 0 0 2px #5a7a8a, 0 1px 5px rgba(0,0,0,.4);
  position:relative;
}
.cluster-marker::after {
  content:'tappe'; position:absolute; bottom:-15px; left:50%; transform:translateX(-50%);
  font-size:0.55rem; font-weight:600; color:#5a7a8a; background:#fff; padding:0 4px; border-radius:3px;
  white-space:nowrap; box-shadow:0 1px 2px rgba(0,0,0,.25);
}

/* Orizzonte (luoghi citati) */
.horizon-marker { width:12px; height:12px; border-radius:50%; background:#b98b5e; border:2px solid #fff; box-shadow:0 1px 2px rgba(0,0,0,.3); opacity:0.85; }
.horizon-swatch { width:14px; height:14px; border-radius:50%; background:#b98b5e; border:2px solid #fff; box-shadow:0 0 0 1px #b98b5e; }
.lg-circle.lg-start { background:#27ae60; }

/* Versi */
.mappa-noterella-body .mappa-lg { margin:0.8rem 0 0.8rem 1.5rem; }
.mappa-noterella-body .mappa-l { display:block; }

/* Stampa: mappa pulita per la tesi */
@media print {
  #mappa-toolbar, #mappa-timeline-wrap, #mappa-sidebar, .leaflet-control-zoom, .mappa-intro { display:none !important; }
  #mappa-layout { display:block; }
  #map { height:75vh !important; border:1px solid #999; }
  .map-legend { box-shadow:none; }
}

/* ============================================================
   RIFINITURE: filtro-mese, pulse tappa attiva
   ============================================================ */
#mappa-months { display:flex; flex-wrap:wrap; align-items:center; gap:0.35rem; margin-bottom:0.9rem; }
.months-label { font-size:0.78rem; font-weight:600; color:var(--ui-text-muted); text-transform:uppercase; letter-spacing:0.03em; margin-right:0.3rem; }
.month-chip { font-family:var(--ui-font); font-size:0.82rem; padding:3px 11px; border:1px solid var(--ui-border); border-radius:20px; background:var(--ui-bg); cursor:pointer; color:var(--ui-text); }
.month-chip:hover { background:var(--ui-muted); }
.month-chip.active { background:var(--accent-color); color:#fff; border-color:var(--accent-color); }
.tappa-marker.month-dim { opacity:0.2; }

/* Pulse animato sulla tappa attiva (anello che si espande) */
.tappa-marker.active::after {
  content:''; position:absolute; inset:-3px; border-radius:50%;
  border:2px solid var(--accent-color); pointer-events:none;
  animation: tappaPulse 1.5s ease-out infinite;
}
.tappa-marker.t-battle.active::after { border-color:#a83232; }
.tappa-marker.t-naval.active::after  { border-color:#2c6e8f; }
.tappa-marker.t-start.active::after  { border-color:#27ae60; }
.tappa-marker.t-end.active::after    { border-color:#c0392b; }
@keyframes tappaPulse { 0%{transform:scale(1);opacity:.85} 100%{transform:scale(2);opacity:0} }
