/* Bocatas — stile condiviso dalla pagina dei volontari e da quella admin.
   Notte del lunedì: inchiostro blu notte, giallo luna, rosso pomodoro. */

:root {
  color-scheme: light;
  --night: #16213d;
  --on-night: #f3f1ea;
  --bg: #eceef2;
  --surface: #ffffff;
  --surface-2: #e2e5ec;
  --text: #121a2e;
  --muted: #4f5a72;
  --border: #d3d8e1;
  --border-strong: #121a2e;
  --primary: #c23a1e;
  --primary-hover: #9e2d15;
  --on-primary: #ffffff;
  --primary-soft: #fbe6e0;
  --moon: #f3c24a;
  --success: #1f6b45;
  --success-soft: #dcefe3;
  --danger: #b0281a;
  --danger-soft: #fbe3df;
  --on-danger: #ffffff;
  --focus: #121a2e;
  --radius: 4px;
  --radius-sm: 3px;
  --display: "Chivo", "Segoe UI", "Helvetica Neue", sans-serif;
  --serif: var(--display);
  --sans: "Chivo", "Segoe UI", "Helvetica Neue", sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    color-scheme: dark;
    --night: #0a1022;
    --bg: #0f1628;
    --surface: #172038;
    --surface-2: #222c47;
    --text: #eef1f6;
    --muted: #a3adc4;
    --border: #2a3552;
    --border-strong: #8d98b3;
    --primary: #ff7a5c;
    --primary-hover: #ff9a82;
    --on-primary: #0f1628;
    --primary-soft: #3a1f1c;
    --success: #7fd3a4;
    --success-soft: #16352a;
    --danger: #ff9180;
    --danger-soft: #3b1d1b;
    --on-danger: #0f1628;
    --focus: #f3c24a;
  }
}

/* ---------- Base ---------- */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

/* Su mobile la pagina dei volontari non scorre (né rimbalza); quella admin sì. */
@media (max-width: 640px) {
  html:not(.admin), html:not(.admin) body {
    height: 100%;
    overflow: hidden;
    overscroll-behavior: none;
    touch-action: pan-x pan-y;
  }
}
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

h1, h2 {
  margin: 0 0 0.5rem;
  font-family: var(--display);
  font-weight: 900;
  line-height: 1.05;
  letter-spacing: -0.02em;
}

h1 { font-size: clamp(1.8rem, 6vw, 2.4rem); }
h2 { font-size: 1.25rem; }
p { margin: 0 0 1rem; }
a { color: var(--primary); text-underline-offset: 3px; }
button { font: inherit; color: inherit; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

code {
  padding: 0.1em 0.35em;
  border-radius: 4px;
  background: var(--surface-2);
  font-family: ui-monospace, SFMono-Regular, Consolas, monospace;
  font-size: 0.9em;
}

/* ---------- Barra in alto ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  padding-top: max(12px, env(safe-area-inset-top));
  background: var(--night);
  color: var(--on-night);
  border-bottom: 4px solid var(--moon);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  color: inherit;
  font-family: var(--display);
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.02em;
  text-decoration: none;
}

.brand img { display: block; border-radius: 6px; }

.badge {
  padding: 1px 8px;
  border-radius: 2px;
  background: var(--moon);
  color: #121a2e;
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.topbar-user { display: flex; align-items: center; gap: 14px; min-width: 0; }

.topbar-name {
  overflow: hidden;
  color: var(--on-night);
  opacity: 0.8;
  font-size: 0.95rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-link {
  flex: none;
  min-height: 36px;
  padding: 6px 2px;
  border: 0;
  background: transparent;
  color: var(--on-night);
  font-size: 0.95rem;
  text-decoration: underline;
  text-decoration-color: var(--moon);
  text-underline-offset: 4px;
  cursor: pointer;
}

.topbar-link:hover { text-decoration-color: currentColor; }

/* ---------- Impaginazione ---------- */

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 32px 16px calc(56px + env(safe-area-inset-bottom));
}

main.wide { max-width: 1180px; }

.card {
  padding: 22px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

section > .card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 14px; }

.login {
  max-width: 420px;
  margin: clamp(8px, 6vh, 64px) auto 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.login h1 { font-size: clamp(2.2rem, 8vw, 2.8rem); }

.muted { color: var(--muted); }

.hint {
  margin: 20px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.9rem;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--primary);
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.loading { margin-top: 20vh; color: var(--muted); text-align: center; }

/* ---------- Moduli ---------- */

.stack > * + * { margin-top: 14px; }

.field label { display: block; margin-bottom: 6px; font-size: 0.9rem; font-weight: 600; }
.optional, .nickname { color: var(--muted); font-weight: 400; }
.field-hint { display: block; margin-top: 6px; color: var(--muted); font-size: 0.82rem; }

input, select {
  width: 100%;
  min-height: 46px;
  padding: 10px 12px;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
}

input::placeholder { color: var(--muted); opacity: 0.75; }
input:focus-visible, select:focus-visible { border-color: var(--focus); outline: 1px solid var(--focus); outline-offset: 0; }

.form-error { margin: 0; color: var(--danger); font-size: 0.9rem; font-weight: 600; }
.form-error:empty { display: none; }

.form-grid { display: grid; gap: 14px; }
.form-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }

@media (min-width: 760px) {
  .form-grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .form-grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---------- Pulsanti ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 10px 18px;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font-weight: 700;
  text-align: center;
  text-decoration: none;
  cursor: pointer;
  transition: background-color 0.15s, border-color 0.15s, color 0.15s;
}

.btn:hover { border-color: var(--text); }

.btn.primary { border-color: var(--text); background: var(--text); color: var(--bg); }
.btn.primary:hover { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
.btn:active { transform: translateY(1px); }

.btn.danger { border-color: var(--danger); background: var(--danger); color: var(--on-danger); }

.btn.quiet-danger { border-color: var(--border); color: var(--danger); }
.btn.quiet-danger:hover { border-color: var(--danger); background: var(--danger-soft); }

.btn.block { width: 100%; }
.btn.small { min-height: 36px; padding: 6px 12px; font-size: 0.9rem; }
.btn:disabled { opacity: 0.5; pointer-events: none; }

.icon-btn {
  display: inline-grid;
  flex: none;
  place-items: center;
  width: 44px;
  height: 44px;
  padding: 0;
  border: 2px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.icon-btn:hover { border-color: var(--text); }
.icon-btn:disabled { visibility: hidden; }

.icon-btn.remove { width: 36px; height: 36px; border-color: transparent; color: var(--muted); }
.icon-btn.remove:hover { background: var(--danger-soft); color: var(--danger); }

/* ---------- Turno ---------- */

.shift-head {
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr) 44px;
  align-items: center;
  gap: 8px;
  margin-bottom: 24px;
  text-align: center;
}

.shift-head h1 { margin: 0; }
.shift-head .eyebrow { margin-bottom: 2px; }

.status { grid-column: 1 / -1; margin: 4px 0 0; color: var(--muted); font-size: 0.92rem; }
.status.open { color: var(--success); }

.toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: -4px 0 24px;
}

.inline-field { display: inline-flex; align-items: center; gap: 8px; color: var(--muted); font-size: 0.9rem; }
.inline-field input { width: auto; }

.notice {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface-2);
  font-size: 0.95rem;
  text-align: left;
}

.notice.ok { border-color: transparent; background: var(--success-soft); }

.notice-icon {
  display: grid;
  flex: none;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  color: var(--muted);
}

.notice.ok .notice-icon { background: var(--success); color: var(--surface); }
.notice p { margin: 0; }

[aria-busy="true"] { opacity: 0.6; transition: opacity 0.2s; }

/* Turno dei volontari: posti rimasti e pulsante «Ci sono!» */

.column { max-width: 500px; margin: 0 auto; }
.column.wide { max-width: 720px; }

.turno { display: flex; flex-direction: column; gap: 16px; padding: 28px 24px 24px; border: 2px solid var(--border-strong); text-align: center; }

.spots { display: flex; flex-direction: column; align-items: center; margin: 0; }

.spots-num {
  color: var(--text);
  font-family: var(--display);
  font-size: clamp(4.5rem, 20vw, 6.5rem);
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums lining-nums;
  font-weight: 900;
  line-height: 0.95;
}

.spots.full .spots-num { color: var(--muted); }
.spots-label { margin-top: 6px; color: var(--muted); font-size: 1.05rem; }

.meter { display: flex; gap: 3px; height: 14px; }
.meter span { flex: 1; border-radius: 1px; background: var(--surface-2); }
.meter span.taken { background: var(--text); }
.meter span.mine { background: var(--primary); }

.spots-total { margin: -6px 0 4px; color: var(--muted); font-size: 0.88rem; font-variant-numeric: tabular-nums; }

.btn.big { min-height: 56px; font-size: 1.15rem; }
.btn.big.primary { border-color: var(--primary); background: var(--primary); color: var(--on-primary); }
.btn.big.primary:hover { border-color: var(--primary-hover); background: var(--primary-hover); }

/* Turno nella pagina admin */

.turno-admin { display: grid; gap: 16px; }

.capacity { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px 20px; }
.capacity-text { flex: 1 1 240px; }
.capacity h2 { margin: 0; }
.capacity h2 label { font: inherit; }
.capacity .field-hint { margin: 4px 0 0; font-size: 0.85rem; }

.stepper { display: flex; flex: none; align-items: center; gap: 8px; }

.stepper input {
  width: 80px;
  font-family: var(--display);
  font-size: 1.5rem;
  font-variant-numeric: tabular-nums lining-nums;
  font-weight: 600;
  text-align: center;
}

/* Con :disabled .icon-btn sparisce (frecce dei turni); qui deve restare visibile. */
.stepper .icon-btn:disabled { visibility: visible; opacity: 0.35; cursor: default; }

.link-btn {
  padding: 0;
  border: 0;
  background: none;
  color: var(--primary);
  font-weight: 600;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
}

#a-members-card { display: flex; flex-direction: column; gap: 14px; }

.giro-head { display: flex; align-items: baseline; gap: 10px; }
.giro-head h2 { flex: 1; min-width: 0; margin: 0; overflow-wrap: anywhere; }

.count {
  flex: none;
  color: var(--muted);
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

.count.full { color: var(--primary); }

.slots { display: grid; margin: 0; padding: 0; list-style: none; counter-reset: slot; }

.slot {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 52px;
  padding: 6px 0;
  border-top: 1px solid var(--border);
}

.slot:first-child { border-top: 0; }

.slot-name { flex: 1; min-width: 0; font-weight: 500; overflow-wrap: anywhere; }
.slot-name small { display: block; color: var(--muted); font-size: 0.8rem; font-weight: 400; }

.avatar {
  display: grid;
  flex: none;
  place-items: center;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

/* Toni tenui, testo scuro: si distinguono senza gridare. */
.av-0 { background: #fbd9cf; color: #7a1f0c; }
.av-1 { background: #d6e3d0; color: #2c4a26; }
.av-2 { background: #d5dde8; color: #273a55; }
.av-3 { background: #e7d6e0; color: #523046; }
.av-4 { background: #f8e3a6; color: #5a4300; }
.av-5 { background: #dcd7cf; color: #3d3730; }

.giro-note { margin: 0; color: var(--muted); font-size: 0.9rem; text-align: center; }

/* Menu e pulsante sulla stessa riga se c'è spazio, altrimenti il pulsante va sotto. */
.add-row { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 4px; }
.add-row select { flex: 999 1 190px; min-width: 0; }
.add-row .btn { flex: 1 0 auto; }

/* ---------- Admin ---------- */

.tabs {
  display: flex;
  gap: 24px;
  margin: -8px 0 28px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
}

.tabs::-webkit-scrollbar { display: none; }

.tab {
  flex: none;
  min-height: 46px;
  margin-bottom: -1px;
  padding: 8px 2px;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { border-bottom: 3px solid var(--primary); color: var(--text); }

.pill {
  display: inline-block;
  min-width: 1.6em;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.8rem;
  text-align: center;
}

.list-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.list-head h2 { margin: 0; }
.list-head input { max-width: 320px; }

.people-list { margin: 0; padding: 0; list-style: none; }

.person {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 12px;
  padding: 14px 0;
  border-top: 1px solid var(--border);
}

.person:first-child { border-top: 0; }
.person-main { flex: 1; min-width: 0; }
.person-name { font-weight: 600; overflow-wrap: anywhere; }
.person-meta { color: var(--muted); font-size: 0.85rem; overflow-wrap: anywhere; }

.empty { margin: 12px 0 4px; color: var(--muted); text-align: center; }

/* ---------- Finestre di dialogo e notifiche ---------- */

dialog {
  width: min(460px, calc(100vw - 32px));
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  border: 2px solid var(--border-strong);
}

dialog::backdrop { background: rgb(10 16 34 / 0.6); }

.dialog-body { padding: 24px; }
.dialog-message { margin: 0; font-size: 1.02rem; }
.dialog-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; margin-top: 22px; }
.dialog-actions .push-left { margin-right: auto; }

.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 50;
  max-width: calc(100vw - 32px);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  background: var(--text);
  color: var(--bg);
  font-weight: 500;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 8px);
  transition: opacity 0.2s, transform 0.2s;
}

.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { background: #1f6b45; color: #fff; }
.toast.error { background: #b0281a; color: #fff; }

.offscreen { position: fixed; top: 0; left: -9999px; opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; }
}

@media print {
  .topbar, .tabs, .toolbar, .icon-btn, .add-row, .capacity, .toast { display: none !important; }
  body { background: #fff; color: #000; }
  .card { border-color: #bbb; break-inside: avoid; }
}
