/* ============================================================
   CivicFlow Eventi — portale pubblico
   Mobile-first, contrasto adeguato, nessuna dipendenza esterna.
   ============================================================ */

:root {
  --bg: #f4f5fa;
  --surface: #ffffff;
  --ink: #2f3349;
  --muted: #68788B;
  --line: #e3e6ef;
  --primary: #2c5fe0;
  --primary-dark: #1f47ab;
  --success: #157347;
  --success-bg: #e8f6ee;
  --warning: #8a6100;
  --warning-bg: #fff5e0;
  --danger: #b02a37;
  --danger-bg: #fdeaec;
  --radius: 12px;
}

* { box-sizing: border-box; }

/* Nessuna immagine puo' sfondare il contenitore, qualunque misura
   abbia il file caricato. Vale anche per le locandine, che arrivano
   dai Comuni in ogni formato. */
img { max-width: 100%; height: auto; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.55;
}

.container { width: 100%; max-width: 720px; margin: 0 auto; padding: 0 16px; }

.skip-link {
  position: absolute; left: -9999px; top: 0;
  background: var(--ink); color: #fff; padding: 10px 16px; z-index: 10;
}
.skip-link:focus { left: 8px; top: 8px; }

/* Intestazione e piè di pagina ------------------------------------------ */
.site-header { background: var(--ink); color: #fff; padding: 14px 0; }
.site-header .container { display: flex; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.brand { font-size: 12px; letter-spacing: .12em; text-transform: uppercase; opacity: .75; }
.brand-comune { font-size: 18px; font-weight: 700; }

.site-footer { margin: 48px 0 32px; color: var(--muted); font-size: 14px; text-align: center; }
.site-footer p { margin: 4px 0; }

/* Blocchi --------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  margin: 20px 0;
}

.cover { width: 100%; height: auto; border-radius: var(--radius); margin-top: 20px; display: block; }

h1 { font-size: 28px; line-height: 1.25; margin: 24px 0 8px; }
h2 { font-size: 20px; margin: 28px 0 10px; }
h3 { font-size: 17px; margin: 20px 0 8px; }
.lead { color: var(--muted); font-size: 17px; margin: 0 0 16px; }

.meta { list-style: none; padding: 0; margin: 0; }
.meta li { display: flex; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.meta li:last-child { border-bottom: 0; }
.meta .label { color: var(--muted); min-width: 108px; flex: 0 0 108px; }

.prose { white-space: pre-line; }

/* Stato ----------------------------------------------------------------- */
.badge {
  display: inline-block; padding: 4px 12px; border-radius: 999px;
  font-size: 13px; font-weight: 600;
}
.badge-ok { background: var(--success-bg); color: var(--success); }
.badge-warn { background: var(--warning-bg); color: var(--warning); }
.badge-off { background: var(--danger-bg); color: var(--danger); }

.notice {
  border-left: 4px solid var(--primary);
  background: var(--surface);
  border-radius: 8px;
  padding: 14px 16px;
  margin: 20px 0;
}
.notice-success { border-color: var(--success); background: var(--success-bg); }
.notice-warning { border-color: var(--warning); background: var(--warning-bg); }
.notice-error { border-color: var(--danger); background: var(--danger-bg); }

/* Modulo ---------------------------------------------------------------- */
.field { margin-bottom: 18px; }
.field label { display: block; font-weight: 600; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: 14px; margin-bottom: 6px; }

input[type="text"], input[type="email"], input[type="tel"], input[type="number"], select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: inherit;
  background: #fff;
}
textarea { min-height: 96px; }

input:focus, select:focus, textarea:focus, button:focus, a:focus {
  outline: 3px solid rgba(44, 95, 224, .35);
  outline-offset: 2px;
}

.field .error { color: var(--danger); font-size: 14px; margin-top: 6px; }
.has-error input, .has-error select, .has-error textarea { border-color: var(--danger); }

.choice { display: flex; align-items: flex-start; gap: 10px; margin-bottom: 8px; }
.choice input { margin-top: 4px; }
.choice label { font-weight: 400; margin: 0; }

.hp { position: absolute; left: -9999px; width: 1px; height: 1px; overflow: hidden; }

.btn {
  display: inline-block; width: 100%; text-align: center;
  background: var(--primary); color: #fff;
  border: 0; border-radius: 8px;
  padding: 15px 22px; font: inherit; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.btn:hover { background: var(--primary-dark); }
.btn-secondary { background: #fff; color: var(--ink); border: 1px solid var(--line); }
.btn-secondary:hover { background: #f2f4f9; }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid var(--danger); }
.btn-danger:hover { background: var(--danger-bg); }
.btn + .btn { margin-top: 10px; }

/* Conferma -------------------------------------------------------------- */
.code-box { text-align: center; padding: 24px; }
.code-box .label { color: var(--muted); font-size: 13px; letter-spacing: .08em; text-transform: uppercase; }
.code-box .code { font-size: 34px; font-weight: 700; letter-spacing: .06em; margin-top: 4px; }
.qr { display: block; margin: 20px auto 8px; max-width: 240px; width: 100%; height: auto; }
.qr-hint { text-align: center; color: var(--muted); font-size: 14px; }

.link-box {
  word-break: break-all; background: #f7f8fc; border: 1px solid var(--line);
  border-radius: 8px; padding: 12px; font-size: 14px;
}

@media (min-width: 640px) {
  .btn { width: auto; }
  .btn + .btn { margin-top: 0; margin-left: 10px; }
  h1 { font-size: 34px; }
}

/* Pagina incorporata nel sito del Comune -------------------------------- */
/* L'intestazione ripeterebbe il nome dell'ente già presente nel sito che
   ospita. Il piè di pagina resta, perché contiene l'informativa. */
.is-embedded .site-header { display: none; }
.is-embedded .site-footer { margin-top: 28px; font-size: 13px; }
/* La firma del prodotto non compare dentro il sito di chi eroga il servizio. */
.is-embedded .only-standalone { display: none; }
.is-embedded main.container { padding-top: 4px; }
.is-embedded h1 { margin-top: 8px; }

@media print {
  .site-header, .site-footer, .btn, form { display: none !important; }
  .card { border: 0; }
}

/* ============================================================
   Vetrina degli eventi (home)
   ============================================================
   Griglia che parte a una colonna e cresce con lo spazio. Niente
   media query sulle larghezze dei dispositivi: auto-fill decide da
   sé quante colonne stanno, e continua a funzionare su misure che
   nel 2026 non esistono ancora. */

.event-grid {
  list-style: none;
  margin: 0 0 24px;
  padding: 0;
  display: grid;
  gap: 16px;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
}

.event-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

.event-link {
  display: flex;
  flex-direction: column;
  height: 100%;
  color: inherit;
  text-decoration: none;
}

/* Il focus deve vedersi sulla scheda intera, non sul solo testo:
   chi naviga da tastiera deve capire dove si trova. */
.event-link:focus-visible {
  outline: 3px solid var(--primary);
  outline-offset: -3px;
}

.event-link:hover .event-title { text-decoration: underline; }

.event-cover {
  display: block;
  width: 100%;
  /* Rapporto fisso: le locandine arrivano di ogni misura e senza
     questo la griglia diventa una scala. */
  aspect-ratio: 16 / 10;
  object-fit: cover;
  background: #eef0f7;
}

.event-cover-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 40px;
  font-weight: 700;
  color: #aeb6cc;
  background: linear-gradient(135deg, #eef0f7, #e3e7f3);
}

.event-body {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px 14px;
  flex: 1;
}

.event-comune {
  font-size: 12px;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
}

.event-title { font-weight: 700; line-height: 1.3; }

.event-meta { font-size: 14px; color: var(--muted); }

/* Spinge le etichette in fondo, così le schede restano allineate
   anche quando i titoli hanno lunghezze diverse. */
.event-status { margin-top: auto; padding-top: 8px; }

.pill {
  display: inline-block;
  padding: 2px 10px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
}

/* Lo stato non è affidato al solo colore: il testo lo dice comunque. */
.pill-open   { background: var(--success-bg); color: var(--success); }
.pill-few    { background: var(--warning-bg); color: var(--warning); }
.pill-closed { background: #eceef4;           color: var(--muted); }

/* Il richiamo alla prenotazione già fatta: è il motivo per cui la
   maggior parte delle persone torna sul portale. */
.card-highlight { border-left: 4px solid var(--primary); }
.card-highlight .h-inline { margin-top: 0; font-size: 19px; }

/* ============================================================
   VARCO — il lettore di chi sta alla porta
   ============================================================
   La pagina del varco divide il lettore con la scheda «Check-in» del
   backoffice: stesso file JavaScript, stessi identificatori, stessi
   nomi di classe. Quelli sono nati nel tema del gestionale, quindi qui
   vanno ridefiniti — sono una manciata, ed e' molto meno lavoro che
   tenere due lettori.
   ============================================================ */

.d-none { display: none !important; }
.d-flex { display: flex; }
.justify-content-between { justify-content: space-between; }
.align-items-center { align-items: center; }
.text-muted { color: var(--muted); }
.small { font-size: 14px; }

.alert {
  border-radius: var(--radius);
  padding: 12px 14px;
  margin-bottom: 16px;
  border: 1px solid var(--line);
  font-weight: 600;
}
.alert-success { background: var(--success-bg); border-color: var(--success); color: var(--success); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning); color: var(--warning); }
.alert-danger  { background: var(--danger-bg);  border-color: var(--danger);  color: var(--danger); }
.alert-info    { background: #eaf0fd;           border-color: var(--primary); color: var(--primary-dark); }

.list-group-item {
  display: flex;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
  background: none;
  border-left: 0; border-right: 0; border-top: 0;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
}
.list-group-item:last-child { border-bottom: 0; }
.list-group-item-action { cursor: pointer; }
.list-group-item-action:hover { background: #f2f4f9; }

.bg-label-success   { background: var(--success-bg); color: var(--success); }
.bg-label-secondary { background: #eceef4;           color: var(--muted); }

/* Alla porta si guarda lo schermo di sfuggita, spesso al buio: i numeri
   che contano stanno grandi, e il riquadro della fotocamera prende tutta
   la larghezza che c'e'. */
/* La ricerca a mano e' un campo come gli altri: nel portale non
   compariva perche' finora non c'era niente da cercare. */
input[type="search"] {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  color: inherit;
  background: #fff;
}

.gate-head { display: flex; justify-content: space-between; align-items: baseline; gap: 12px; flex-wrap: wrap; }
.gate-head h1 { margin-top: 0; }
.gate-head p { margin: 0; }
.gate-count { font-size: 32px; font-weight: 700; line-height: 1; }

.gate-camera {
  position: relative;
  width: 100%;
  aspect-ratio: 4 / 3;
  background: #11131c;
  border-radius: var(--radius);
  overflow: hidden;
}
.gate-camera video { width: 100%; height: 100%; object-fit: cover; }

.gate-result dt { color: var(--muted); font-weight: 400; }
.gate-result dd { margin: 0 0 10px; font-weight: 600; }

/* Il PIN si digita al buio, con i guanti, con una fila davanti. */
.pin-input {
  font-size: 32px;
  letter-spacing: .35em;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

#recentList, #searchResults { list-style: none; padding: 0; margin: 0; }

/* ============================================================
   Appuntamenti — elenco servizi, calendario, slot
   ============================================================ */
.list { display: grid; gap: 12px; }
.service-link { display: block; text-decoration: none; color: inherit; }
.service-link:hover .service-name, .service-link:focus-visible .service-name { color: var(--primary); text-decoration: underline; }
.service-name { display: block; font-size: 1.15rem; font-weight: 700; }
.service-desc { display: block; margin-top: 4px; }
.service-meta { display: block; margin-top: 6px; font-size: .875rem; color: var(--muted); }

.calendar { padding: 16px; }
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.cal-nav { display: inline-flex; align-items: center; justify-content: center; width: 40px; height: 40px;
  border-radius: 50%; font-size: 1.5rem; text-decoration: none; color: var(--primary); }
.cal-nav:hover { background: var(--bg); }
.cal-nav.is-off { color: var(--line); }
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; text-align: center; }
.cal-wd { font-size: .75rem; color: var(--muted); font-weight: 600; padding-bottom: 4px; }
.cal-day { display: flex; align-items: center; justify-content: center; aspect-ratio: 1; max-height: 48px;
  border-radius: 8px; color: var(--muted); font-size: .95rem; }
a.cal-day { color: var(--primary); background: #eaf0fd; font-weight: 700; text-decoration: none; }
a.cal-day:hover { background: #d6e2fb; }
a.cal-day.is-selected { background: var(--primary); color: #fff; }

.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 8px; margin-bottom: 24px; }
.slot { display: block; padding: 10px 0; text-align: center; border: 1px solid var(--primary); border-radius: 8px;
  color: var(--primary); font-weight: 600; text-decoration: none; background: var(--surface); }
.slot:hover { background: #eaf0fd; }
.slot.is-selected { background: var(--primary); color: #fff; }
