/* ============================================================
   InfoComuni — Eventi interattivi
   Calendar grid + Map markers + Geolocation + Day filter
   v1.0 — 2026-05-27
   ============================================================ */

/* ============ COLORI PER TIPOLOGIA (coerente con legenda) ============ */
:root {
  --ev-color-patronale:   #3b82f6;
  --ev-color-festival:    #a855f7;
  --ev-color-sagra:       #10b981;
  --ev-color-fiera:       #f59e0b;
  --ev-color-sport:       #ef4444;
  --ev-color-cultura:     #0b2340;
  --ev-color-musica:      #ec4899;
  --ev-color-processione: #14a39e;
  --ev-color-regata:      #06b6d4;
  --ev-color-rievocazione:#7c3aed;
  --ev-color-carnevale:   #f97316;
}

/* ============ CALENDAR MONTH GRID ============ */
#calMonthGrid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
  border: 1px solid rgba(11,35,64,0.08);
  box-shadow: 0 4px 14px rgba(11,35,64,0.05);
}

.cal-day-head {
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: #6b7585;
  text-align: center;
  text-transform: uppercase;
  padding: 6px 2px;
}

.cal-day {
  position: relative;
  aspect-ratio: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 8px;
  font: inherit;
  font-size: 13.5px;
  font-weight: 600;
  color: #0b2340;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, transform 0.1s ease;
  padding: 0;
  min-height: 38px;
}
.cal-day:hover {
  background: #f3f4f7;
  border-color: rgba(243,184,64,0.32);
}
.cal-day:active { transform: scale(0.96); }
.cal-day.is-other-month {
  color: #cbd5e1;
  cursor: default;
  pointer-events: none;
}
.cal-day.is-today {
  background: rgba(243,184,64,0.14);
  border-color: rgba(243,184,64,0.55);
  font-weight: 800;
}
.cal-day.has-events {
  background: #f8fafc;
  border-color: rgba(11,35,64,0.10);
}
.cal-day.has-events::after {
  content: "";
  position: absolute;
  bottom: 4px; left: 50%;
  transform: translateX(-50%);
  width: 4px; height: 4px;
  border-radius: 50%;
  background: var(--ev-dot-color, #1f8763);
}
/* Multiple events: stack di 3 dots max */
.cal-day.has-events--multi::after { width: 16px; height: 4px; border-radius: 2px; }

.cal-day.is-selected {
  background: linear-gradient(135deg, #1f8763 0%, #14a169 100%);
  color: #fff !important;
  border-color: #0d4f3f;
  font-weight: 800;
  box-shadow: 0 4px 14px rgba(31,135,99,0.32);
}
.cal-day.is-selected::after { background: #f3b840 !important; }

/* ============ DAY EVENT PANEL ============ */
.cal-day-panel {
  background: linear-gradient(160deg, #ffffff 0%, #f8fafc 100%);
  border: 1px solid rgba(11,35,64,0.08);
  border-radius: 14px;
  padding: 20px 22px;
  margin: 18px 0 0;
  box-shadow: 0 4px 18px rgba(11,35,64,0.06);
}
.cal-day-panel__head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap;
  margin-bottom: 14px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(11,35,64,0.06);
}
.cal-day-panel__title {
  margin: 0;
  font-size: 17px; font-weight: 800;
  color: #0b2340;
  letter-spacing: -0.012em;
}
.cal-day-panel__title strong { color: #1f8763; }
.cal-day-panel__close {
  background: rgba(11,35,64,0.06);
  border: 0;
  width: 32px; height: 32px;
  border-radius: 50%;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  color: #475063;
  font-size: 18px;
  line-height: 1;
}
.cal-day-panel__close:hover { background: rgba(11,35,64,0.14); }
.cal-day-panel__list {
  display: grid; gap: 10px;
  list-style: none; margin: 0; padding: 0;
}
.cal-day-event {
  display: grid;
  grid-template-columns: 6px 1fr auto;
  gap: 14px;
  align-items: center;
  padding: 12px 14px;
  background: #fff;
  border: 1px solid rgba(11,35,64,0.07);
  border-radius: 10px;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.cal-day-event:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(11,35,64,0.08);
  border-color: rgba(243,184,64,0.32);
}
.cal-day-event__dot {
  width: 6px; height: 100%;
  min-height: 40px;
  border-radius: 3px;
  background: var(--ev-dot, #1f8763);
}
.cal-day-event__body { min-width: 0; }
.cal-day-event__name {
  font-size: 14.5px; font-weight: 700; color: #0b2340;
  margin: 0 0 3px;
  line-height: 1.25;
}
.cal-day-event__meta {
  font-size: 12.5px; color: #6b7585;
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
}
.cal-day-event__tipo {
  display: inline-block;
  font-size: 10.5px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--ev-bg, #def8e9);
  color: var(--ev-fg, #0f7a47);
}
.cal-day-event__distance {
  font-size: 12px;
  color: #1f8763;
  font-weight: 700;
  background: #e8f5ef;
  padding: 3px 10px;
  border-radius: 999px;
  white-space: nowrap;
}

/* ============ GEOLOCATION BUTTON ============ */
.ev-geoloc {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 18px;
  background: linear-gradient(135deg, #1f8763 0%, #14a169 100%);
  color: #fff;
  border: 0;
  border-radius: 999px;
  font: inherit; font-size: 13.5px; font-weight: 700;
  cursor: pointer;
  box-shadow: 0 4px 14px rgba(31,135,99,0.28);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.ev-geoloc:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(31,135,99,0.38);
}
.ev-geoloc:active { transform: scale(0.97); }
.ev-geoloc[data-state="loading"] { opacity: 0.7; pointer-events: none; }
.ev-geoloc[data-state="active"] {
  background: linear-gradient(135deg, #f3b840 0%, #e3a02c 100%);
  color: #0b2340;
}
.ev-geoloc__icon {
  width: 16px; height: 16px;
  display: inline-flex; align-items: center; justify-content: center;
}
.ev-geoloc__icon svg { width: 100%; height: 100%; }
.ev-geoloc[data-state="loading"] .ev-geoloc__icon svg { animation: ic-spin 0.9s linear infinite; }

.ev-geoloc-row {
  display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  margin: 14px 0 0;
}
.ev-geoloc-status {
  font-size: 12.5px; color: #6b7585;
}
.ev-geoloc-status[data-state="ok"] { color: #1f8763; font-weight: 600; }
.ev-geoloc-status[data-state="error"] { color: #c12848; font-weight: 600; }

/* ============ LEAFLET MAP CONTAINER ============ */
#calMap {
  height: 380px;
  border-radius: 12px;
  overflow: hidden;
  border: 1px solid rgba(11,35,64,0.08);
  box-shadow: 0 4px 14px rgba(11,35,64,0.05);
}
#calMap.is-loading {
  background: linear-gradient(90deg, #eef0f4 0%, #f8fafc 50%, #eef0f4 100%);
  background-size: 200% 100%;
  animation: ic-skel 1.4s linear infinite;
}
.leaflet-popup-content {
  font: 13px/1.5 system-ui, -apple-system, sans-serif;
  color: #0b2340;
  margin: 10px 12px;
}
.leaflet-popup-content strong { color: #0b2340; font-weight: 800; }
.leaflet-popup-content .ev-popup-tipo {
  display: inline-block;
  font-size: 10.5px; font-weight: 700;
  letter-spacing: 0.04em; text-transform: uppercase;
  padding: 2px 8px; border-radius: 999px;
  background: var(--ev-bg-popup, #def8e9);
  color: var(--ev-fg-popup, #0f7a47);
  margin: 4px 0 6px;
}
.leaflet-popup-content .ev-popup-meta {
  font-size: 12px; color: #6b7585;
}

/* Marker custom (div icon) */
.ev-marker {
  width: 26px; height: 26px;
  border-radius: 50% 50% 50% 0;
  background: var(--ev-marker-bg, #1f8763);
  transform: rotate(-45deg);
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  border: 2px solid #fff;
  position: relative;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease;
}
.ev-marker::after {
  content: ""; width: 8px; height: 8px;
  background: #fff; border-radius: 50%;
  position: absolute; top: 7px; left: 7px;
}
.ev-marker:hover { transform: rotate(-45deg) scale(1.15); }
.ev-marker--user {
  background: #f3b840;
  border-color: #fff;
  width: 22px; height: 22px;
  border-radius: 50%;
  transform: none;
  box-shadow: 0 0 0 6px rgba(243,184,64,0.30), 0 2px 6px rgba(0,0,0,0.30);
  animation: ev-user-pulse 1.8s ease-out infinite;
}
.ev-marker--user::after { display: none; }
@keyframes ev-user-pulse {
  0%   { box-shadow: 0 0 0 0    rgba(243,184,64,0.55), 0 2px 6px rgba(0,0,0,0.30); }
  70%  { box-shadow: 0 0 0 14px rgba(243,184,64,0.00), 0 2px 6px rgba(0,0,0,0.30); }
  100% { box-shadow: 0 0 0 0    rgba(243,184,64,0.00), 0 2px 6px rgba(0,0,0,0.30); }
}

/* ============ MOBILE ============ */
@media (max-width: 768px) {
  #calMonthGrid { padding: 10px; gap: 3px; }
  .cal-day { font-size: 12.5px; min-height: 34px; }
  .cal-day-panel { padding: 16px 14px; }
  .cal-day-panel__title { font-size: 15.5px; }
  .cal-day-event { grid-template-columns: 6px 1fr; }
  .cal-day-event__distance { grid-column: 1 / -1; justify-self: start; margin-top: 4px; }
  #calMap { height: 300px; }
}
