/* =====================================================================
   GREST 2026 — Stylesheet base
   Design tokens (CSS variables), reset moderno, utility e componenti.
   Mobile-first: il device principale è il telefono di un animatore.
   ===================================================================== */

/* ---------- Design tokens (Material/iOS, light) ---------------------- */
:root {
  color-scheme: light;

  /* Colori squadre */
  --team-rossi:  #E53935;
  --team-gialli: #FBC02D;
  --team-verdi:  #43A047;
  --team-blu:    #1E88E5;

  /* Brand: scala estesa */
  --brand-50:     #E3F2FD;
  --brand-100:    #BBDEFB;
  --brand-300:    #64B5F6;
  --brand-500:    #1E88E5;  /* primario default */
  --brand-700:    #1565C0;  /* primario "deep" per testo / hover */
  --brand-900:    #0D47A1;
  --brand:        var(--brand-500);
  --brand-dark:   var(--brand-700);
  --brand-soft:   var(--brand-50);
  --on-brand:     #ffffff;  /* testo che va sopra al brand */

  /* Superfici (Material Surface scale: 0 → 4) */
  --surface-0:    #fafafa;   /* page background */
  --surface-1:    #ffffff;   /* card / dialog */
  --surface-2:    #f4f5f7;   /* input field, panel discreto */
  --surface-3:    #eceef1;   /* hover state, separator panel */
  --surface-4:    #e3e6ea;
  /* alias storici */
  --bg:          var(--surface-0);
  --surface:     var(--surface-1);
  --surface-alt: var(--surface-2);

  /* Bordi */
  --border:        #dde1e6;
  --border-soft:   #eef0f3;
  --border-strong: #c4cad1;
  --divider:       rgba(0,0,0,.08);

  /* Testo (emphasis Material 3) */
  --text:        #0f1419;          /* high emphasis */
  --text-muted:  #4a5560;          /* medium */
  --text-faint:  #8a95a0;          /* low / disabled */
  --on-surface:  var(--text);

  /* Stato (saturati per status, soft per background) */
  --ok:        #2E7D32;
  --ok-soft:   #E8F5E9;
  --warn:      #ED6C02;
  --warn-soft: #FFF3E0;
  --err:       #D32F2F;
  --err-soft:  #FFEBEE;
  --info:      var(--brand-500);
  --info-soft: var(--brand-50);

  /* Spazi (scala 4px) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-10: 40px;
  --space-12: 48px;

  /* Radii */
  --radius-1:    8px;
  --radius-2:    12px;
  --radius-3:    16px;
  --radius-4:    20px;
  --radius-pill: 999px;

  /* Ombre (Material elevation 1 → 5) */
  --shadow-1: 0 1px 2px rgba(15,20,25,.05), 0 1px 1px rgba(15,20,25,.04);
  --shadow-2: 0 2px 6px rgba(15,20,25,.06), 0 2px 4px rgba(15,20,25,.04);
  --shadow-3: 0 6px 16px rgba(15,20,25,.10), 0 4px 8px rgba(15,20,25,.05);
  --shadow-4: 0 12px 28px rgba(15,20,25,.14), 0 8px 12px rgba(15,20,25,.06);
  --shadow-focus: 0 0 0 3px rgba(30,136,229,.30);

  /* Tipografia */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
               "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  --fs-1: 11px;
  --fs-2: 13px;
  --fs-3: 15px;
  --fs-4: 17px;
  --fs-5: 21px;
  --fs-6: 28px;
  --fs-7: 34px;
  --fw-regular: 400;
  --fw-medium:  500;
  --fw-semibold:600;
  --fw-bold:    700;

  /* Motion */
  --motion-fast:  120ms;
  --motion-base:  200ms;
  --motion-slow:  320ms;
  --ease-out:     cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in-out:  cubic-bezier(0.4, 0, 0.2, 1);

  /* Layout */
  --header-h:    56px;
  --bottomnav-h: 72px;
  --content-max: 1100px;
  --tap-min:     44px;       /* iOS minimum tap target */
  --tap-comf:    56px;       /* comodo */
}

/* ---------- Dark mode tokens ----------------------------------------- */
:root[data-theme="dark"] {
  color-scheme: dark;

  --brand-50:     #102A43;
  --brand-100:    #1E3A5F;
  --brand-300:    #4DA3FF;
  --brand-500:    #4DA3FF;
  --brand-700:    #82B1FF;
  --brand-900:    #BBDEFB;
  --brand:        var(--brand-500);
  --brand-dark:   var(--brand-700);
  --brand-soft:   rgba(77,163,255,.14);
  --on-brand:     #0a1929;

  /* Surface scale (Material dark + leggera tinta brand su elevation alta) */
  --surface-0:    #0e1217;
  --surface-1:    #161b22;
  --surface-2:    #1c232b;
  --surface-3:    #232b35;
  --surface-4:    #2a3340;
  --bg:          var(--surface-0);
  --surface:     var(--surface-1);
  --surface-alt: var(--surface-2);

  --border:        #2a323d;
  --border-soft:   #20262e;
  --border-strong: #3a4452;
  --divider:       rgba(255,255,255,.08);

  --text:        rgba(255,255,255,.92);
  --text-muted:  rgba(255,255,255,.62);
  --text-faint:  rgba(255,255,255,.40);
  --on-surface:  var(--text);

  --ok-soft:   rgba(46,125,50,.18);
  --warn-soft: rgba(237,108,2,.18);
  --err-soft:  rgba(211,47,47,.18);
  --info-soft: rgba(77,163,255,.18);

  --shadow-1: 0 1px 2px rgba(0,0,0,.4);
  --shadow-2: 0 2px 6px rgba(0,0,0,.45);
  --shadow-3: 0 6px 16px rgba(0,0,0,.55);
  --shadow-4: 0 12px 28px rgba(0,0,0,.65);
  --shadow-focus: 0 0 0 3px rgba(77,163,255,.45);
}

/* Auto dark per chi NON ha settato manualmente il tema */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --brand-50:     #102A43;
    --brand-100:    #1E3A5F;
    --brand-300:    #4DA3FF;
    --brand-500:    #4DA3FF;
    --brand-700:    #82B1FF;
    --brand-900:    #BBDEFB;
    --brand:        var(--brand-500);
    --brand-dark:   var(--brand-700);
    --brand-soft:   rgba(77,163,255,.14);
    --on-brand:     #0a1929;
    --surface-0:    #0e1217;
    --surface-1:    #161b22;
    --surface-2:    #1c232b;
    --surface-3:    #232b35;
    --surface-4:    #2a3340;
    --bg:           var(--surface-0);
    --surface:      var(--surface-1);
    --surface-alt:  var(--surface-2);
    --border:        #2a323d;
    --border-soft:   #20262e;
    --border-strong: #3a4452;
    --divider:       rgba(255,255,255,.08);
    --text:        rgba(255,255,255,.92);
    --text-muted:  rgba(255,255,255,.62);
    --text-faint:  rgba(255,255,255,.40);
    --ok-soft:   rgba(46,125,50,.18);
    --warn-soft: rgba(237,108,2,.18);
    --err-soft:  rgba(211,47,47,.18);
    --info-soft: rgba(77,163,255,.18);
    --shadow-1: 0 1px 2px rgba(0,0,0,.4);
    --shadow-2: 0 2px 6px rgba(0,0,0,.45);
    --shadow-3: 0 6px 16px rgba(0,0,0,.55);
    --shadow-4: 0 12px 28px rgba(0,0,0,.65);
    --shadow-focus: 0 0 0 3px rgba(77,163,255,.45);
  }
}

/* ---------- Reset moderno -------------------------------------------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: var(--font-sans);
  font-size: var(--fs-3);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  -webkit-tap-highlight-color: transparent;
  font-feature-settings: "cv11", "ss01";   /* Inter: numeri tabulari belli */
  transition: background-color var(--motion-base) var(--ease-in-out),
              color var(--motion-base) var(--ease-in-out);
}
img, svg { max-width: 100%; display: block; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; background: transparent; border: 0; }
a { color: var(--brand-dark); text-decoration: none; transition: color var(--motion-fast); }
a:hover { color: var(--brand); text-decoration: underline; }

/* Focus visibili (accessibilità + dark mode) */
:focus-visible {
  outline: none;
  box-shadow: var(--shadow-focus);
  border-radius: var(--radius-1);
}

/* Scrollbar discreta (webkit) */
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border-radius: var(--radius-pill);
  border: 2px solid var(--surface-0);
}
*::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

/* ---------- App shell: header + top-nav (desktop) + bottom-nav (mobile) */
.app-header {
  position: sticky;
  top: 0; left: 0; right: 0;
  min-height: var(--header-h);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  backdrop-filter: saturate(180%) blur(12px);
  -webkit-backdrop-filter: saturate(180%) blur(12px);
  border-bottom: 1px solid var(--border-soft);
  display: flex;
  align-items: center;
  padding: 0 var(--space-4);
  gap: var(--space-3);
  z-index: 30;
}
.app-header .brand {
  font-weight: var(--fw-bold);
  font-size: var(--fs-4);
  color: var(--text);
  letter-spacing: -.015em;
  display: flex; align-items: center; gap: var(--space-2);
}
.app-header .brand::before {
  content: "";
  width: 28px; height: 28px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand-500), var(--brand-700));
  display: inline-block;
  box-shadow: var(--shadow-1);
}
.app-header .spacer { flex: 1; }

.app-header .user-chip {
  display: flex; align-items: center; gap: var(--space-2);
  font-size: var(--fs-2);
  color: var(--text-muted);
}
.app-header .user-chip strong { color: var(--text); }

/* Bottone toggle tema */
.theme-toggle {
  width: 38px; height: 38px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  color: var(--text-muted);
  transition: background var(--motion-fast), color var(--motion-fast);
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }
.theme-toggle svg { width: 20px; height: 20px; }
.theme-toggle .icon-sun { display: none; }
.theme-toggle .icon-moon { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-sun { display: inline; }
:root[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .icon-sun { display: inline; }
  :root:not([data-theme="light"]) .theme-toggle .icon-moon { display: none; }
}

/* Pulsante menu ☰ (solo mobile: vedi media query) */
.nav-toggle {
  display: none;
  appearance: none; border: none; background: transparent;
  color: var(--text); font-size: 22px; line-height: 1; cursor: pointer;
  padding: 4px 10px; margin-right: 2px; border-radius: 8px;
}
.nav-toggle:hover { background: var(--surface-2); }
.nav-toggle:active { transform: scale(0.95); }

/* Top-nav (desktop/tablet): pill scrollabili */
.app-nav {
  background: var(--surface);
  border-bottom: 1px solid var(--border-soft);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  position: sticky;
  top: var(--header-h);
  z-index: 20;
}
.app-nav ul {
  display: flex;
  gap: 4px;
  list-style: none;
  margin: 0;
  padding: 8px var(--space-3);
  white-space: nowrap;
  max-width: var(--content-max);
  margin: 0 auto;
}
.app-nav a {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-2);
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  transition: background var(--motion-fast), color var(--motion-fast), transform var(--motion-fast);
}
.app-nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}
.app-nav a:active { transform: scale(0.97); }
.app-nav a.is-active {
  background: var(--brand-soft);
  color: var(--brand-dark);
}

main.app-main {
  max-width: var(--content-max);
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) calc(var(--space-10) + var(--space-4));
}

/* Bottom-nav (solo mobile): tap target XL */
.bottom-nav {
  display: none;
  position: fixed;
  left: 0; right: 0; bottom: 0;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-top: 1px solid var(--border-soft);
  z-index: 30;
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
.bottom-nav ul {
  display: grid;
  grid-template-columns: repeat(var(--bn-cols, 5), 1fr);
  list-style: none;
  margin: 0;
  padding: 0;
}
.bottom-nav a {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  height: var(--bottomnav-h);
  font-size: 12px;
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  transition: color var(--motion-fast), background var(--motion-fast);
  min-width: 0;             /* permette al testo di restringere senza overflow */
  padding: 0 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.bottom-nav a > span:last-child {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.bottom-nav a:hover { text-decoration: none; color: var(--text); }
.bottom-nav a:active { background: var(--surface-2); }
.bottom-nav a.is-active { color: var(--brand-dark); }
.bottom-nav a.is-active .bn-ico {
  background: var(--brand-soft);
  transform: scale(1.05);
}
.bottom-nav .bn-ico {
  width: 52px; height: 30px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: var(--radius-pill);
  font-size: 22px;
  line-height: 1;
  transition: background var(--motion-fast), transform var(--motion-fast);
}

/* ---------- Tipografia ----------------------------------------------- */
h1 { font-size: var(--fs-6); font-weight: var(--fw-bold); margin: 0 0 var(--space-4); letter-spacing: -.022em; line-height: 1.15; }
h2 { font-size: var(--fs-5); font-weight: var(--fw-semibold); margin: var(--space-6) 0 var(--space-3); letter-spacing: -.015em; line-height: 1.2; }
h3 { font-size: var(--fs-4); font-weight: var(--fw-semibold); margin: var(--space-5) 0 var(--space-2); letter-spacing: -.005em; line-height: 1.3; }
p  { margin: 0 0 var(--space-3); }
.text-muted { color: var(--text-muted); }
.text-faint { color: var(--text-faint); }
.text-small { font-size: var(--fs-2); }
.text-mono  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
strong, b { font-weight: var(--fw-semibold); }

/* ---------- Card ----------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-3);
  padding: var(--space-5);
  box-shadow: var(--shadow-1);
  transition: box-shadow var(--motion-base) var(--ease-in-out),
              border-color var(--motion-base) var(--ease-in-out),
              background var(--motion-base) var(--ease-in-out);
}
.card + .card { margin-top: var(--space-4); }
.card.is-interactive { cursor: pointer; }
.card.is-interactive:hover { box-shadow: var(--shadow-2); border-color: var(--border); }
.card-title {
  font-size: var(--fs-1);
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  margin: 0 0 var(--space-3);
}

/* ---------- Form ----------------------------------------------------- */
.field { display: block; margin-bottom: var(--space-4); }
.field-label {
  display: block;
  font-size: var(--fs-2);
  font-weight: var(--fw-medium);
  margin-bottom: 6px;
  color: var(--text);
}
.input, .select, .textarea {
  width: 100%;
  padding: 11px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  background: var(--surface);
  font-size: var(--fs-3);
  color: var(--text);
  transition: border-color var(--motion-fast), box-shadow var(--motion-fast),
              background var(--motion-fast);
  min-height: var(--tap-min);
}
.input::placeholder, .textarea::placeholder { color: var(--text-faint); }
.input:hover, .select:hover, .textarea:hover { border-color: var(--border-strong); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: var(--shadow-focus);
}
.input[disabled] { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }
select.input { appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='%236a737d'%3E%3Cpath d='M5.23 7.21a.75.75 0 011.06.02L10 11.06l3.71-3.83a.75.75 0 011.08 1.04l-4.25 4.4a.75.75 0 01-1.08 0L5.21 8.27a.75.75 0 01.02-1.06z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; background-size: 18px 18px;
  padding-right: 38px;
}
:root[data-theme="dark"] select.input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='rgba(255,255,255,0.62)'%3E%3Cpath d='M5.23 7.21a.75.75 0 011.06.02L10 11.06l3.71-3.83a.75.75 0 011.08 1.04l-4.25 4.4a.75.75 0 01-1.08 0L5.21 8.27a.75.75 0 01.02-1.06z'/%3E%3C/svg%3E");
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) select.input {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20' fill='rgba(255,255,255,0.62)'%3E%3Cpath d='M5.23 7.21a.75.75 0 011.06.02L10 11.06l3.71-3.83a.75.75 0 011.08 1.04l-4.25 4.4a.75.75 0 01-1.08 0L5.21 8.27a.75.75 0 01.02-1.06z'/%3E%3C/svg%3E");
  }
}

/* ---------- Bottoni (Material-style) -------------------------------- */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--tap-min);
  padding: 10px 18px;
  border: 1px solid transparent;
  border-radius: var(--radius-2);
  font-size: var(--fs-3);
  font-weight: var(--fw-semibold);
  letter-spacing: -.005em;
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
  box-shadow: var(--shadow-1);
  transition: background var(--motion-fast) var(--ease-in-out),
              transform var(--motion-fast) var(--ease-out),
              box-shadow var(--motion-fast),
              border-color var(--motion-fast),
              color var(--motion-fast);
  user-select: none;
  -webkit-user-select: none;
  overflow: hidden;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: scale(0.97); box-shadow: var(--shadow-1); }
.btn[disabled] { opacity: .5; cursor: not-allowed; transform: none !important; }

.btn-primary {
  background: var(--brand);
  color: var(--on-brand);
  border-color: transparent;
  box-shadow: var(--shadow-2);
}
.btn-primary:hover {
  background: var(--brand-dark);
  border-color: transparent;
  box-shadow: var(--shadow-3);
}
.btn-primary:active { box-shadow: var(--shadow-1); }

.btn-danger {
  background: var(--err);
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-2);
}
.btn-danger:hover { background: #B71C1C; box-shadow: var(--shadow-3); }

.btn-success {
  background: #1D7044;
  color: #fff;
  border-color: transparent;
  box-shadow: var(--shadow-2);
}
.btn-success:hover { background: #155c37; box-shadow: var(--shadow-3); }
.btn-success:active { box-shadow: var(--shadow-1); }
.btn-success:disabled { opacity: .65; cursor: default; }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--brand-dark);
  box-shadow: none;
}
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; box-shadow: none; }

.btn-block { display: flex; width: 100%; }

.btn-icon {
  width: var(--tap-min); height: var(--tap-min);
  padding: 0;
  border-radius: var(--radius-pill);
}

/* ---------- Badge ---------------------------------------------------- */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: 11px;
  font-weight: var(--fw-semibold);
  text-transform: uppercase;
  letter-spacing: .04em;
  background: var(--surface-3);
  color: var(--text-muted);
  line-height: 1.6;
}
.badge-rossi  { background: var(--team-rossi);  color: #fff; }
.badge-gialli { background: var(--team-gialli); color: #1f2328; }
.badge-verdi  { background: var(--team-verdi);  color: #fff; }
.badge-blu    { background: var(--team-blu);    color: #fff; }
.badge-allergia { background: var(--err); color: #fff; }
.badge-ok    { background: var(--ok-soft);   color: var(--ok); }
.badge-warn  { background: var(--warn-soft); color: var(--warn); }
.badge-info  { background: var(--info-soft); color: var(--brand-dark); }

/* Badge "nota staff": cliccabile, ricavato come <button>.
   Lasciamo il padding/font-size del .badge ma resettiamo lo stile button. */
button.badge-nota-staff {
  background: var(--info-soft);
  color: var(--brand-dark);
  border: 1px dashed var(--brand-dark);
  cursor: pointer;
  font-family: inherit;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
button.badge-nota-staff:hover,
button.badge-nota-staff:focus {
  filter: brightness(0.97);
  outline: none;
}

/* Sotto-titoli dentro la modale Note */
.modal .ns-h4 {
  margin: var(--space-3) 0 var(--space-2);
  font-size: var(--fs-2);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
}

/* Box che mostra la nota staff completa dentro la modale */
.nota-staff-box {
  background: var(--surface-2);
  border-left: 3px solid var(--brand-dark);
  padding: var(--space-3);
  border-radius: var(--radius-2);
  font-size: var(--fs-2);
  color: var(--text);
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 240px;
  overflow: auto;
  margin-bottom: var(--space-3);
}

/* ---------- Toast ---------------------------------------------------- */
.toast-host {
  position: fixed;
  left: 50%;
  bottom: calc(var(--space-6) + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  display: flex;
  flex-direction: column-reverse;
  gap: var(--space-2);
  z-index: 1000;
  pointer-events: none;
}
/* Su mobile lascia spazio per la bottom-nav fissa, così i toast sono visibili */
@media (max-width: 720px) {
  .toast-host {
    bottom: calc(var(--bottomnav-h) + var(--space-3) + env(safe-area-inset-bottom, 0px));
    width: auto;
    max-width: calc(100vw - 24px);
  }
  /* Toast più compatto su telefono: meno padding, niente min-width fissa,
     così occupa solo lo spazio necessario al testo. */
  .toast {
    padding: 8px 12px;
    min-width: 0;
    max-width: 100%;
    font-size: var(--fs-2);
    border-radius: var(--radius-1);
  }
  .toast-with-action {
    gap: var(--space-2);
    padding: 6px 6px 6px 12px;
  }
  .toast-undo {
    padding: 6px 12px;
  }
}
.toast {
  pointer-events: auto;
  background: var(--surface-4);
  color: var(--text);
  padding: 12px 18px;
  border-radius: var(--radius-2);
  font-size: var(--fs-2);
  font-weight: var(--fw-medium);
  box-shadow: var(--shadow-3);
  border: 1px solid var(--border);
  animation: toast-in var(--motion-base) var(--ease-out);
  min-width: 220px;
  text-align: center;
}
.toast-ok   { background: var(--ok);   color: #fff; border-color: transparent; }
.toast-err  { background: var(--err);  color: #fff; border-color: transparent; }
.toast-warn { background: var(--warn); color: #fff; border-color: transparent; }
.toast-with-action {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: 10px 10px 10px 18px;
  text-align: left;
}
.toast-with-action .toast-msg { flex: 1; }
.toast-undo {
  background: rgba(255,255,255,0.22);
  color: inherit;
  border: 0;
  padding: 8px 14px;
  border-radius: var(--radius-pill);
  font: inherit;
  font-weight: var(--fw-semibold);
  cursor: pointer;
  white-space: nowrap;
  transition: background var(--motion-fast);
}
.toast-undo:hover { background: rgba(255,255,255,0.35); }
.toast:not([class*="toast-ok"]):not([class*="toast-err"]):not([class*="toast-warn"]) .toast-undo {
  background: var(--brand-soft);
  color: var(--brand-dark);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(12px) scale(0.96); }
  to   { opacity: 1; transform: translateY(0) scale(1); }
}

/* ---------- Loader / spinner ----------------------------------------- */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--surface-3);
  border-top-color: var(--brand);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-3);
  padding: var(--space-8);
  color: var(--text-muted);
  font-size: var(--fs-2);
}

/* Skeleton (placeholder mentre carica) */
.skeleton {
  background: linear-gradient(90deg, var(--surface-2), var(--surface-3), var(--surface-2));
  background-size: 200% 100%;
  animation: skel 1.4s ease-in-out infinite;
  border-radius: var(--radius-1);
}
@keyframes skel { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Login page ------------------------------------------------ */
.login-page {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: var(--space-5);
  background:
    radial-gradient(800px 600px at -10% -20%, var(--brand-soft) 0%, transparent 60%),
    radial-gradient(700px 500px at 110% 110%, var(--brand-soft) 0%, transparent 60%),
    var(--bg);
}
.login-card {
  width: min(420px, 100%);
  background: var(--surface);
  border-radius: var(--radius-4);
  padding: var(--space-8) var(--space-6);
  box-shadow: var(--shadow-4);
  border: 1px solid var(--border-soft);
}
.login-card h1 {
  text-align: center;
  font-size: var(--fs-5);
  margin: 0 0 var(--space-2);
}
.login-card .subtitle {
  text-align: center;
  color: var(--text-muted);
  margin-bottom: var(--space-6);
  font-size: var(--fs-2);
}
.login-card .error-msg {
  background: var(--err-soft);
  color: var(--err);
  border: 1px solid color-mix(in srgb, var(--err) 30%, transparent);
  border-radius: var(--radius-2);
  padding: var(--space-3);
  font-size: var(--fs-2);
  margin-bottom: var(--space-3);
  display: none;
}
.login-card .error-msg.is-shown { display: block; }
.login-foot {
  text-align: center;
  font-size: var(--fs-1);
  color: var(--text-faint);
  margin-top: var(--space-5);
}

/* ---------- Tabella -------------------------------------------------- */
.table-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-3);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}
table.tbl {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-2);
}
.tbl th, .tbl td {
  padding: 12px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}
.tbl tr:last-child td { border-bottom: 0; }
.tbl th {
  font-weight: var(--fw-semibold);
  color: var(--text-muted);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: .06em;
  background: var(--surface-2);
}
.tbl tr { transition: background var(--motion-fast); }
.tbl tbody tr:hover td { background: var(--surface-2); }
.tbl a { color: var(--text); }
.tbl a:hover { color: var(--brand-dark); }

/* Mobile: la tabella iscritti diventa una lista di schede (label:valore),
   come la pagina Medico — niente scroll orizzontale. */
@media (max-width: 720px) {
  .table-wrap { overflow-x: visible; }
  .tbl-cards { display: block; width: 100%; font-size: 14px; }
  .tbl-cards thead { display: none; }
  .tbl-cards tbody { display: block; width: 100%; }
  .tbl-cards tr {
    display: block;
    width: 100%;
    box-sizing: border-box;
    padding: 12px 14px;
    border-bottom: 1px solid var(--border);
  }
  .tbl-cards tr:last-child { border-bottom: 0; }
  .tbl-cards tbody tr:hover td { background: transparent; }
  .tbl-cards td {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    box-sizing: border-box;
    padding: 5px 0;
    border: 0;
    text-align: right;
  }
  .tbl-cards td::before {
    content: attr(data-label);
    color: var(--text-muted);
    font-weight: var(--fw-semibold);
    font-size: 12px;
    text-transform: none;
    letter-spacing: 0;
    text-align: left;
    white-space: nowrap;
  }
  .tbl-cards td:empty { display: none; }
  /* Nome in evidenza in cima alla scheda */
  .tbl-cards td.isc-cell-name {
    display: block;
    text-align: left;
    margin-bottom: 6px;
    padding-bottom: 8px;
    border-bottom: 1px solid var(--border-soft);
  }
  .tbl-cards td.isc-cell-name::before { display: none; }
  .tbl-cards td.isc-cell-name a strong { font-size: 16px; }
}

/* ---------- Stat tile (Material/iOS feel) --------------------------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-3);
}
.stat {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-3);
  padding: var(--space-4) var(--space-3);
  text-align: center;
  box-shadow: var(--shadow-1);
  transition: transform var(--motion-base) var(--ease-out),
              box-shadow var(--motion-base);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-2); }
.stat .stat-num {
  font-size: var(--fs-7);
  font-weight: var(--fw-bold);
  color: var(--text);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.02em;
}
.stat .stat-lbl {
  margin-top: var(--space-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .08em;
  font-weight: var(--fw-medium);
  color: var(--text-muted);
}

/* ---------- Utilities ------------------------------------------------ */
.row { display: flex; gap: var(--space-3); align-items: center; }
.row-wrap { flex-wrap: wrap; }
.col { display: flex; flex-direction: column; gap: var(--space-3); }
.spacer { flex: 1; }
.hidden { display: none !important; }
.mt-2 { margin-top: var(--space-2); }
.mt-3 { margin-top: var(--space-3); }
.mt-4 { margin-top: var(--space-4); }
.mt-5 { margin-top: var(--space-5); }

/* ---------- Mobile tuning -------------------------------------------- */
@media (max-width: 720px) {
  main.app-main {
    padding: var(--space-4) var(--space-3)
             calc(var(--bottomnav-h) + var(--space-6) + env(safe-area-inset-bottom, 0px));
  }
  .app-header .user-chip strong { display: none; }
  .app-header .user-chip { font-size: var(--fs-1); }

  /* Su mobile la nav completa diventa un menu a tendina aperto dal ☰ */
  .nav-toggle { display: inline-flex; align-items: center; }
  .app-nav {
    display: none;
    position: fixed;
    top: var(--header-h);
    left: 0; right: 0;
    max-height: calc(100vh - var(--header-h));
    overflow-y: auto;
    border-bottom: 1px solid var(--border);
    box-shadow: 0 14px 30px rgba(0, 0, 0, .20);
    z-index: 40;
  }
  .app-nav.is-open { display: block; }
  .app-nav ul {
    flex-direction: column;
    gap: 2px;
    padding: 8px;
    white-space: normal;
    max-width: none;
  }
  .app-nav a { display: flex; padding: 13px 14px; font-size: var(--fs-3); border-radius: 10px; }
  .bottom-nav { display: block; }

  h1 { font-size: var(--fs-5); }
  h2 { font-size: var(--fs-4); }
  .btn { padding: 12px 18px; }
  .card { padding: var(--space-4); }
  .stat .stat-num { font-size: var(--fs-6); }
  .stat-grid { grid-template-columns: repeat(2, 1fr); gap: var(--space-2); }
}

/* Schermi stretti: compatta la bottom-nav per far stare comodamente 6 tab
   (Home/Presenze/Iscritti/Squadre/Medico/Scrivi) su una sola riga. */
@media (max-width: 420px) {
  .bottom-nav a { font-size: 11px; gap: 2px; }
  .bottom-nav .bn-ico {
    width: 44px; height: 28px;
    font-size: 20px;
  }
}
@media (max-width: 360px) {
  .bottom-nav a { font-size: 10px; }
  .bottom-nav .bn-ico { width: 38px; height: 26px; font-size: 18px; }
}

/* =====================================================================
   MODULO COMUNICAZIONI
   ===================================================================== */
.com-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.com-toolbar .seg { display: inline-flex; }
.com-toolbar .seg button {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 8px 14px;
  cursor: pointer;
  font: inherit;
  font-weight: var(--fw-medium);
  color: var(--text-muted);
}
.com-toolbar .seg button:first-child { border-radius: var(--radius-1) 0 0 var(--radius-1); }
.com-toolbar .seg button:last-child  { border-radius: 0 var(--radius-1) var(--radius-1) 0; }
.com-toolbar .seg button + button { border-left: 0; }
.com-toolbar .seg button.is-active {
  background: var(--brand);
  color: var(--on-brand);
  border-color: var(--brand);
}

.com-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--space-3);
  align-items: start;
}
.com-grid > section:nth-child(3) { grid-column: 1 / -1; }
@media (max-width: 900px) {
  .com-grid { grid-template-columns: 1fr; }
}

/* Selezione gruppo classe */
.com-groups {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
}
.com-group {
  background: var(--surface-2);
  border: 2px solid var(--border-soft);
  border-radius: var(--radius-2);
  padding: var(--space-3);
  text-align: center;
  cursor: pointer;
  transition: all var(--motion-fast) var(--ease-out);
  color: var(--text);
}
.com-group:hover { background: var(--surface-3); border-color: var(--border); }
.com-group.is-active {
  background: var(--brand-soft);
  border-color: var(--brand);
  color: var(--brand-dark);
  box-shadow: var(--shadow-1);
}
.com-group-label { font-weight: var(--fw-bold); font-size: var(--fs-4); }
.com-group-sub   { font-size: 11px; color: var(--text-muted); margin-top: 2px; }
.com-group.is-active .com-group-sub { color: var(--brand-dark); opacity: .8; }
@media (max-width: 480px) {
  .com-groups { grid-template-columns: 1fr; }
}

/* Lista destinatari */
.com-dest-list {
  list-style: none; margin: 0; padding: 0;
  display: flex; flex-direction: column;
  max-height: 480px; overflow-y: auto;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  background: var(--surface-2);
}
.com-dest {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border-soft);
}
.com-dest:last-child { border-bottom: 0; }
.com-dest:hover { background: var(--surface); }
.com-dest-main { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.com-dest-name { color: var(--text); }
.com-dest-name:hover { color: var(--brand-dark); text-decoration: none; }
.com-dest-actions { display: flex; gap: 6px; flex-shrink: 0; }

/* Template editor & list */
.com-tpl-actions { display: flex; gap: var(--space-2); flex-wrap: wrap; }
.com-tpl-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.com-tpl {
  background: var(--surface-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  padding: var(--space-3);
}
.com-tpl-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); flex-wrap: wrap; margin-bottom: 4px; }
.com-tpl-body {
  margin: 6px 0 0;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-1);
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: var(--fs-2);
  white-space: pre-wrap;
  word-break: break-word;
}
.com-tpl-seg {
  display: inline-block;
  background: var(--info-soft);
  color: var(--brand-dark);
  padding: 1px 6px;
  border-radius: var(--radius-1);
  cursor: pointer;
  font-family: var(--font-mono);
  font-size: 11px;
  transition: background var(--motion-fast);
}
.com-tpl-seg:hover { background: var(--brand-soft); }

/* Storico */
.com-storico { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: var(--space-2); }
.com-storico-item {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  padding: var(--space-3);
}
.com-storico-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); flex-wrap: wrap; }
.com-storico-meta { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; margin-top: 4px; }
.com-storico-body {
  margin: 8px 0 0;
  background: var(--surface-2);
  border-radius: var(--radius-1);
  padding: 8px 10px;
  font-family: var(--font-sans);
  font-size: var(--fs-2);
  white-space: pre-wrap;
  word-break: break-word;
}

/* form-row "check" inline */
.form-row .check {
  display: inline-flex; align-items: center; gap: var(--space-2);
  font-size: var(--fs-2); color: var(--text);
}
.form-row .check input { transform: scale(1.2); }

/* Riduzione motion per chi preferisce */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* ---------- Modulo Presenze ----------------------------------------- */

/* Tab "Presenze | Uscite" — segmented control grande in alto */
.pre-tabs {
  display: inline-flex;
  margin-bottom: var(--space-3);
}
.pre-tabs button {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 22px;
  cursor: pointer;
  font: inherit;
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  transition: background var(--motion-fast), color var(--motion-fast);
}
.pre-tabs button:first-child { border-radius: var(--radius-1) 0 0 var(--radius-1); }
.pre-tabs button:last-child  { border-radius: 0 var(--radius-1) var(--radius-1) 0; }
.pre-tabs button + button { border-left: 0; }
.pre-tabs button.is-active {
  background: var(--brand);
  color: var(--on-brand);
  border-color: var(--brand);
}

/* Toolbar: griglia giorni del Grest */
.pre-toolbar-data {
  display: flex;
  gap: var(--space-2);
  align-items: flex-start;
  margin-bottom: var(--space-3);
}

/* Griglia 3 righe × 5 colonne giorni */
.day-grid {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-3);
  padding: var(--space-2);
  box-shadow: var(--shadow-1);
  transition: padding var(--motion-fast);
}
.day-grid.is-collapsed { padding: 4px; }

/* Pillola compatta del giorno selezionato (modalità collapsed) */
.day-collapsed {
  width: 100%;
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 10px 14px;
  background: var(--brand);
  color: var(--on-brand);
  border: 0;
  border-radius: var(--radius-2);
  cursor: pointer;
  font: inherit;
  font-weight: var(--fw-medium);
  font-size: var(--fs-3);
  text-align: left;
  transition: filter var(--motion-fast);
}
.day-collapsed:hover { filter: brightness(1.05); }
.day-collapsed:active { filter: brightness(0.95); }
.day-collapsed-cal { font-size: 20px; line-height: 1; }
.day-collapsed-main { flex: 1; display: inline-flex; align-items: center; gap: 6px; }
.day-collapsed-main .badge {
  background: rgba(255,255,255,0.22);
  color: var(--on-brand);
}
.day-collapsed-hint {
  font-size: var(--fs-2);
  opacity: 0.85;
  white-space: nowrap;
}
.day-row {
  display: grid;
  grid-template-columns: 32px 1fr;
  gap: var(--space-2);
  align-items: stretch;
}
.day-row-label {
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: var(--fw-bold);
  font-size: var(--fs-2);
  color: var(--text-muted);
  letter-spacing: .02em;
}
.day-row-cells {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
}
.day-cell {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  min-height: 52px;
  padding: 6px 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-1);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: background var(--motion-fast), border-color var(--motion-fast),
              color var(--motion-fast), transform var(--motion-fast);
}
.day-cell:hover {
  background: var(--surface-2);
  border-color: var(--border-strong);
}
.day-cell:active { transform: scale(0.96); }
.day-cell.is-today {
  border-color: var(--brand);
  box-shadow: inset 0 -2px 0 var(--brand);
}
.day-cell.is-active {
  background: var(--brand);
  color: var(--on-brand);
  border-color: var(--brand);
  box-shadow: var(--shadow-2);
}
.day-cell.is-active .day-name,
.day-cell.is-active .day-num { color: var(--on-brand); }
.day-cell.is-gita .day-flag {
  position: absolute;
  top: 2px; right: 3px;
  font-size: 10px;
  line-height: 1;
}
.day-cell.is-gita.is-active .day-flag { filter: brightness(1.5); }
.day-name {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  font-weight: var(--fw-medium);
}
.day-num {
  font-size: 17px;
  font-weight: var(--fw-bold);
  line-height: 1;
}

@media (max-width: 540px) {
  .day-row-label { font-size: 11px; }
  .day-cell { min-height: 46px; padding: 4px 2px; }
  .day-num  { font-size: 15px; }
  .day-name { font-size: 9px; }
}

/* Filtri collapsable */
.pre-filtri-wrap {
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-2);
  padding: 4px var(--space-3);
  margin-bottom: var(--space-3);
}
.pre-filtri-wrap > summary {
  cursor: pointer;
  padding: 8px 0;
  font-weight: var(--fw-medium);
  color: var(--text);
  list-style: none;
  display: flex;
  align-items: center;
  gap: 6px;
}
.pre-filtri-wrap > summary::before {
  content: "▸";
  display: inline-block;
  transition: transform var(--motion-fast);
  color: var(--text-muted);
}
.pre-filtri-wrap[open] > summary::before { transform: rotate(90deg); }
.pre-filtri-wrap > summary::-webkit-details-marker { display: none; }
.pre-filtri-count { color: var(--brand-dark); font-size: var(--fs-2); }

.pre-filtri {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  padding-bottom: var(--space-3);
}
.pre-filtro { display: flex; flex-direction: column; gap: 4px; }
.pre-filtro-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-muted);
  font-weight: var(--fw-medium);
}
.pre-filtri .seg { display: inline-flex; flex-wrap: wrap; gap: 0; }
.pre-filtri .seg button {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 6px 12px;
  font: inherit;
  font-size: var(--fs-2);
  color: var(--text-muted);
  cursor: pointer;
}
.pre-filtri .seg button + button { border-left: 0; }
.pre-filtri .seg button:first-child { border-radius: var(--radius-1) 0 0 var(--radius-1); }
.pre-filtri .seg button:last-child  { border-radius: 0 var(--radius-1) var(--radius-1) 0; }
.pre-filtri .seg button.is-active {
  background: var(--brand);
  color: var(--on-brand);
  border-color: var(--brand);
}
.pre-filtri .seg button:hover:not(.is-active) { background: var(--surface-2); color: var(--text); }

.pre-search-row { margin-bottom: var(--space-3); }
.pre-search-row .input { width: 100%; }

/* Sezione "Uscite/Pranzo": header con etichetta + contatori */
.usc-section { margin-bottom: var(--space-5); }
.usc-section-head {
  display: flex; align-items: center; gap: var(--space-2);
  margin-bottom: var(--space-2);
  font-size: var(--fs-3);
  flex-wrap: wrap;
}

/* Stats pranzo: tre tile grandi in alto */
.pranzo-stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}

/* Riga "in lista pranzo": evidenziata */
.pre-row.is-pranzo { border-color: rgba(30,136,229,.4); background: var(--info-soft); }

/* Modal generico (dialog di conferma motivo) */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: var(--space-4);
  animation: modal-fade var(--motion-base) var(--ease-out);
}
@keyframes modal-fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-3);
  padding: var(--space-5);
  max-width: 480px;
  width: 100%;
  box-shadow: var(--shadow-4);
  animation: modal-pop var(--motion-base) var(--ease-out);
}
@keyframes modal-pop {
  from { transform: translateY(8px) scale(0.97); opacity: 0; }
  to   { transform: translateY(0)    scale(1);    opacity: 1; }
}
.modal h3 { margin: 0 0 var(--space-2); }
.modal p { margin: 0 0 var(--space-3); }
.modal textarea.input { width: 100%; }
.modal textarea.is-error { border-color: var(--err); box-shadow: 0 0 0 3px rgba(211,47,47,.18); }
.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: var(--space-2);
  margin-top: var(--space-4);
}
.modal-wide { max-width: 560px; }

/* ============ Tab NOTE (presenze) ============ */
.note-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  flex-wrap: wrap;
}
.note-head-title {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.note-row { align-items: flex-start; }
.note-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: var(--space-2);
}
.note-tag {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-pill);
  font-size: 12px;
  font-weight: 500;
  line-height: 1.3;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
}
.note-tag .note-tag-ico { font-size: 13px; }
.note-tag .note-tag-lbl { font-weight: 600; }

.note-tag-in {
  background: rgba(30,136,229,0.10);
  border-color: rgba(30,136,229,0.35);
  color: #1565c0;
}
.note-tag-out {
  background: rgba(245,124,0,0.12);
  border-color: rgba(245,124,0,0.40);
  color: #ef6c00;
}
.note-tag-pranzo {
  background: rgba(198,40,40,0.10);
  border-color: rgba(198,40,40,0.35);
  color: #c62828;
}
.note-tag-altro {
  background: var(--surface-2);
  border-color: var(--border);
  color: var(--text-muted);
}
.note-tag-infortunio {
  background: rgba(198,40,40,0.10);
  border-color: rgba(198,40,40,0.40);
  color: #c62828;
}
.note-tag-comp {
  background: rgba(106,27,154,0.10);
  border-color: rgba(106,27,154,0.38);
  color: #6a1b9a;
}

/* Chip nota con azioni (Modifica / Elimina) nella sezione Note. */
.note-chip-wrap {
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.note-chip-actions {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.note-chip-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 26px;
  height: 26px;
  padding: 0;
  font-size: 13px;
  line-height: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
}
.note-chip-btn:hover { background: var(--surface-2); color: var(--text); }
.note-chip-del:hover {
  background: rgba(198,40,40,0.10);
  border-color: rgba(198,40,40,0.40);
  color: #c62828;
}

/* Sotto-tab della sezione Note (Presenze / Infortunio / Comportamento):
   segmented control a tutta larghezza, con la tab attiva ben evidenziata. */
.note-subtabs {
  display: flex;
  width: 100%;
  margin-bottom: var(--space-3);
}
.note-subtabs button {
  flex: 1;
  border: 1px solid var(--border);
  background: var(--surface);
  padding: 10px 12px;
  cursor: pointer;
  font: inherit;
  font-weight: var(--fw-medium);
  color: var(--text-muted);
  transition: background var(--motion-fast), color var(--motion-fast);
}
.note-subtabs button:first-child { border-radius: var(--radius-1) 0 0 var(--radius-1); }
.note-subtabs button:last-child  { border-radius: 0 var(--radius-1) var(--radius-1) 0; }
.note-subtabs button + button { border-left: 0; }
.note-subtabs button:hover:not(.is-active) { background: var(--surface-2); color: var(--text); }
.note-subtabs button.is-active {
  background: var(--brand);
  color: var(--on-brand);
  border-color: var(--brand);
  font-weight: var(--fw-semibold);
}

/* Contenitore azioni dell'intestazione note (pulsante "+ …") */
.note-head-actions {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  flex-wrap: wrap;
}

/* Modal Nuova nota: form interno */
.nn-label {
  display: block;
  margin: var(--space-3) 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.nn-label:first-child { margin-top: 0; }
.modal .nn-seg {
  display: flex;
  gap: 4px;
  background: var(--surface-2);
  padding: 4px;
  border-radius: var(--radius-pill);
  margin-bottom: var(--space-2);
}
.modal .nn-seg button {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-2);
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--motion-fast) var(--ease-out);
}
.modal .nn-seg button.is-active {
  background: var(--surface);
  color: var(--brand-dark);
  box-shadow: var(--shadow-1);
}
.nn-row {
  display: flex;
  gap: var(--space-3);
}
.nn-col { flex: 1; }

.nn-suggest {
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  background: var(--surface);
  max-height: 220px;
  overflow-y: auto;
  box-shadow: var(--shadow-1);
}
.nn-suggest-item {
  display: flex;
  flex-direction: column;
  width: 100%;
  text-align: left;
  background: transparent;
  border: none;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.nn-suggest-item:last-child { border-bottom: none; }
.nn-suggest-item:hover { background: var(--surface-2); }
.nn-suggest-name { font-weight: 600; }
.nn-suggest-sub { font-size: 12px; color: var(--text-muted); }
.nn-suggest-empty {
  padding: 12px;
  color: var(--text-muted);
  font-size: var(--fs-2);
  text-align: center;
}

.nn-selected {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: 8px 12px;
  background: var(--info-soft);
  border: 1px solid rgba(30,136,229,0.30);
  border-radius: var(--radius-2);
  margin-top: 4px;
}
.nn-selected-name {
  flex: 1;
  font-weight: 600;
  color: var(--text);
}
.nn-selected-clear {
  background: transparent;
  border: none;
  font-size: 16px;
  color: var(--text-muted);
  cursor: pointer;
  padding: 4px 8px;
  border-radius: var(--radius-1);
}
.nn-selected-clear:hover { background: rgba(0,0,0,0.06); color: var(--err); }

/* legacy fallback per .pre-toolbar (vecchio markup) */
.pre-toolbar {
  position: sticky;
  top: var(--header-h);
  z-index: 5;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: var(--space-3) var(--space-4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
  margin: calc(-1 * var(--space-5)) calc(-1 * var(--space-4)) var(--space-4);
}
.pre-toolbar .seg {
  display: inline-flex;
  background: var(--surface-alt);
  border-radius: var(--radius-pill);
  padding: 2px;
}
.pre-toolbar .seg button {
  border: none;
  background: transparent;
  padding: 6px 14px;
  border-radius: var(--radius-pill);
  font-size: var(--fs-2);
  font-weight: 600;
  color: var(--text-muted);
}
.pre-toolbar .seg button.is-active {
  background: var(--surface);
  color: var(--brand-dark);
  box-shadow: var(--shadow-1);
}
.pre-toolbar .gita-switch {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-size: var(--fs-2);
  color: var(--text-muted);
}
.pre-toolbar .input,
.pre-toolbar .select {
  padding: 8px 10px;
  font-size: var(--fs-2);
  width: auto;
}

/* Striscia statistiche sotto toolbar */
.pre-stats {
  display: flex;
  align-items: stretch;
  gap: var(--space-2);
  margin-bottom: var(--space-4);
}
.pre-stats[hidden] { display: none !important; }
.pre-stats .pre-stats-cells {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(var(--stat-cols, 4), 1fr);
  gap: var(--space-2);
  min-width: 0;
}
.pre-stats .stat {
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-2);
}
.pre-stats .stat .stat-num { font-size: var(--fs-5); }
.pre-stats .stat .stat-lbl { font-size: 10px; }
.btn-print-list {
  align-self: center;
  white-space: nowrap;
  font-weight: var(--fw-semibold);
}
@media (max-width: 480px) {
  .pre-stats { flex-direction: column; }
  .btn-print-list { align-self: flex-end; }
}

/* Lista bambini */
.pre-list {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}
.pre-row {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-2);
  transition: background .15s;
}
.pre-row.is-presente { border-color: rgba(46,125,50,.4); background: rgba(46,125,50,.04); }
.pre-row.is-assente  { border-color: rgba(198,40,40,.4); background: rgba(198,40,40,.04); }

.pre-row .who {
  flex: 1;
  min-width: 0;   /* per permettere ellipsis */
}
.pre-row .who .name {
  font-weight: 600;
  font-size: var(--fs-3);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
/* Nome cliccabile (presente quando l'iscritto ha note): reset stile button.
   Usato anche sulla pagina Info (medico): stesso comportamento del Presenze. */
.pre-row .who button.name.name-clickable,
.med-table .who button.name.name-clickable {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  color: var(--brand-dark);
  text-decoration: underline dotted;
  text-underline-offset: 3px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  text-align: left;
  font-family: inherit;
  font-weight: 600;
  font-size: var(--fs-3);
}
.pre-row .who button.name.name-clickable:hover,
.pre-row .who button.name.name-clickable:focus,
.med-table .who button.name.name-clickable:hover,
.med-table .who button.name.name-clickable:focus {
  filter: brightness(0.9);
  outline: none;
}
.pre-row .who .name-note-ico {
  font-size: 0.9em;
  line-height: 1;
}
.pre-row .who .meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: var(--space-1);
  font-size: var(--fs-1);
  color: var(--text-muted);
  margin-top: 2px;
}
.pre-row .who .meta .badge { font-size: 10px; padding: 1px 8px; }

.pre-row .actions {
  display: flex;
  gap: var(--space-2);
  flex-shrink: 0;
}
.pre-btn {
  width: 56px;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--border);
  border-radius: var(--radius-2);
  background: var(--surface);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-muted);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform .05s, background .15s, border-color .15s, color .15s;
}
.pre-btn:active { transform: scale(0.94); }
.pre-btn.btn-pres.is-active {
  background: var(--ok);
  color: #fff;
  border-color: var(--ok);
}
.pre-btn.btn-ass.is-active {
  background: var(--err);
  color: #fff;
  border-color: var(--err);
}
.pre-btn.btn-reset {
  border-color: var(--border);
  color: var(--text-muted);
  background: var(--surface);
  font-size: 22px;
}
.pre-btn.btn-reset:hover {
  background: var(--surface-2);
  color: var(--text);
}

/* Riga "traccia": orari di ingresso/uscita + utente che ha registrato */
.traccia {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 4px;
  font-size: var(--fs-2);
  color: var(--text);
}
.pre-tr {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
}
.pre-updated {
  font-size: var(--fs-2);
  color: var(--text-muted);
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.pre-updated::before {
  content: '';
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--ok, #2E7D32);
  display: inline-block;
}
@media (max-width: 480px) { .pre-updated { display: none; } }

.pre-tr-in  { color: var(--ok); background: var(--ok-soft); }
.pre-tr-out { color: var(--brand-dark); background: var(--info-soft); }
.pre-tr-ass { color: var(--err); background: var(--err-soft); }
.pre-tr strong { font-weight: var(--fw-semibold); }

/* Sunto info mediche nella scheda pranzo (allergie/intolleranze/altre) */
.pranzo-med {
  display: flex;
  flex-direction: column;
  gap: 3px;
  margin-top: 5px;
  padding: 6px 8px;
  border-left: 3px solid var(--warn);
  border-radius: 6px;
  background: var(--warn-soft, rgba(255,179,0,.12));
  font-size: var(--fs-2);
  line-height: 1.35;
}
.pranzo-med-item { color: var(--text); }
.pranzo-med-item strong { font-weight: var(--fw-semibold); }
.pranzo-med-allergia    { color: var(--err); }
.pranzo-med-allergia strong { color: var(--err); }
.pranzo-med-intolleranza strong { color: var(--brand-dark); }
.pranzo-med-info strong { color: var(--text-muted); }

/* Riga uscita: mostrata sotto la riga del bambino quando c'è uscita da gestire */
.pre-uscita {
  margin-top: var(--space-1);
  padding: var(--space-3);
  border-radius: var(--radius-2);
  background: rgba(21,101,192,.06);
  border: 1px dashed rgba(21,101,192,.4);
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  align-items: center;
}
.pre-uscita .input { flex: 1; min-width: 160px; }

/* Empty state */
.empty {
  text-align: center;
  padding: var(--space-8) var(--space-4);
  color: var(--text-muted);
}
.empty .big { font-size: 48px; margin-bottom: var(--space-2); }

/* Mobile fine-tuning */
@media (max-width: 640px) {
  .pre-stats { grid-template-columns: repeat(4, 1fr); }
  .pre-stats .stat { padding: var(--space-2); }
  .pre-stats .stat .stat-num { font-size: var(--fs-4); }
  .pre-btn { width: 52px; height: 52px; font-size: 24px; }
  .pre-row { padding: var(--space-2) var(--space-3); }
}

/* ---------- Modale "Stampa elenco" --------------------------------- */
.modal-print {
  max-width: 1100px;
  width: 96vw;
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  padding: 0;
  overflow: hidden;
}
.modal-print .modal-print-toolbar {
  display: flex;
  gap: var(--space-2);
  justify-content: flex-end;
  flex-wrap: wrap;
  padding: var(--space-3);
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-2);
}
.print-section-title {
  margin: 6px 0 8px;
  font-size: var(--fs-3);
  font-weight: var(--fw-semibold);
  color: var(--text);
}
.modal-print .print-area {
  padding: var(--space-4);
  overflow: auto;
  flex: 1;
  background: var(--surface);
}
.modal-print .print-head h2 { margin: 0 0 4px; font-size: var(--fs-4); }
.modal-print .print-sub { margin: 0; color: var(--text-muted); }
.modal-print .print-meta { margin: 6px 0 var(--space-4); font-size: 12px; color: var(--text-muted); }
.modal-print .print-foot {
  margin-top: var(--space-4);
  font-size: 11px;
  color: var(--text-muted);
  text-align: right;
}
.print-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
  table-layout: auto;
}
.print-table th, .print-table td {
  border: 1px solid var(--border);
  padding: 4px 6px;
  text-align: left;
  vertical-align: top;
  word-break: break-word;
  overflow-wrap: anywhere;
}
.print-table thead th {
  background: var(--surface-2);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .03em;
  font-size: 11px;
}
.print-table tbody tr:nth-child(even) td { background: var(--surface-2); }

/* @media print: stampo SOLO la modale elenco, niente pagine bianche */
@media print {
  html, body {
    height: auto !important;
    min-height: 0 !important;
    overflow: visible !important;
    margin: 0 !important;
  }
  /* CHIAVE: rimuovo dal flusso TUTTO tranne la modale di stampa.
     Con `visibility:hidden` gli elementi restavano in pagina e generavano
     decine di pagine bianche prima dell'elenco; con `display:none` no.
     Limito la regola a quando è aperta la modale elenco (body ha la classe
     `is-printing-overlay`): così NON interferisce con la stampa diretta di
     altre pagine, es. la scheda medica che usa window.print() senza modale. */
  body.is-printing-overlay > *:not(.print-modal) { display: none !important; }

  .modal-overlay.print-modal {
    position: static !important;
    inset: auto !important;
    display: block !important;
    background: #fff !important;
    padding: 0 !important;
  }
  /* Appiattisco i contenitori flex/scroll a flusso blocco normale (evita
     anche il bug mobile "una riga per pagina"). */
  .modal-overlay.print-modal .modal,
  .modal-overlay.print-modal .modal-print,
  .modal-overlay.print-modal .print-area {
    display: block !important;
    flex: none !important;
    float: none !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: visible !important;
  }
  .modal-overlay.print-modal .modal {
    box-shadow: none !important;
    border: none !important;
    max-width: none !important;
    width: 100% !important;
    border-radius: 0 !important;
    background: #fff !important;
  }
  .modal-print-toolbar,
  .no-print { display: none !important; }
  .print-area { padding: 0 !important; background: #fff !important; }

  /* Paginazione tabella: intestazione ripetuta a ogni pagina, righe intere. */
  .print-table {
    page-break-inside: auto !important;
    width: 100% !important;
    table-layout: auto !important;
  }
  .print-table thead { display: table-header-group !important; }
  .print-table tr { page-break-inside: avoid !important; break-inside: avoid !important; }
  .print-table tbody tr:nth-child(even) td {
    background: #f4f4f4 !important;
    -webkit-print-color-adjust: exact; print-color-adjust: exact;
  }
  .print-table th, .print-table td {
    font-size: 8pt !important;
    padding: 2px 4px !important;
    /* Niente rottura a metà parola: "COGNOME" non deve diventare "COGNO/ME". */
    word-break: normal !important;
    overflow-wrap: normal !important;
  }
  /* Le intestazioni di colonna stanno su una riga sola. */
  .print-table thead th { white-space: nowrap !important; }

  /* SOLO l'elenco (modale di stampa) va in A4 ORIZZONTALE: ha molte colonne
     che in verticale risultavano schiacciate. Uso una "named page" così le
     altre stampe (es. scheda medica) restano in verticale di default. */
  @page elenco { size: A4 landscape; margin: 8mm; }
  .modal-overlay.print-modal .modal { page: elenco !important; }
}

/* Safe-area iOS */
@supports (padding: env(safe-area-inset-top)) {
  .app-header { padding-top: env(safe-area-inset-top); height: calc(var(--header-h) + env(safe-area-inset-top)); }
  body { padding-bottom: env(safe-area-inset-bottom); }
}

/* =====================================================================
   MODULO SQUADRE
   ===================================================================== */
.sq-toolbar {
  display: flex;
  gap: var(--space-3);
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.sq-help {
  border: 1px solid var(--border);
  border-left: 4px solid var(--brand);
  background: var(--surface);
  border-radius: 8px;
  padding: var(--space-2) var(--space-3);
  margin: var(--space-3) 0;
}
.sq-help > summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text);
  list-style: none;
}
.sq-help > summary::-webkit-details-marker { display: none; }
.sq-help[open] > summary { margin-bottom: var(--space-2); }
.sq-help-body p { margin: 0; font-size: 0.9rem; color: var(--text-muted); line-height: 1.5; }
.sq-help-body p + p { margin-top: 8px; }
.sq-help-body strong { color: var(--text); }
.sq-help-body em { font-style: normal; color: var(--text); }
.sq-toolbar .seg { display: inline-flex; gap: 0; }
.sq-toolbar .seg button {
  border: 1px solid var(--border);
  background: var(--surface);
  padding: var(--space-2) var(--space-3);
  cursor: pointer;
  font: inherit;
  color: var(--text-muted);
}
.sq-toolbar .seg button:first-child { border-radius: 6px 0 0 6px; }
.sq-toolbar .seg button:last-child  { border-radius: 0 6px 6px 0; }
.sq-toolbar .seg button + button { border-left: 0; }
.sq-toolbar .seg button.is-active {
  background: var(--brand);
  color: #fff;
  border-color: var(--brand);
}

/* Classifica */
.sq-classifica { display: flex; flex-direction: column; gap: var(--space-3); }
.sq-card {
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: var(--space-3);
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 6px solid var(--sq-color, #999);
  border-radius: 10px;
  padding: var(--space-3);
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}
.sq-rank {
  font-size: 28px;
  font-weight: 700;
  color: var(--sq-color, #555);
  text-align: center;
}
.sq-name { font-size: var(--fs-4, 18px); font-weight: 600; }
.sq-meta { color: var(--text-muted); font-size: var(--fs-2, 13px); margin-top: 2px; }
.sq-bar {
  margin-top: 8px;
  height: 8px;
  background: rgba(0,0,0,0.06);
  border-radius: 4px;
  overflow: hidden;
}
.sq-bar-fill {
  height: 100%;
  background: var(--sq-color, #888);
  transition: width 0.4s ease;
}
.sq-points {
  font-size: 32px;
  font-weight: 700;
  color: var(--sq-color, #333);
  min-width: 64px;
  text-align: right;
}

/* Attività */
.sq-attivita { display: flex; flex-direction: column; gap: var(--space-3); }
.sq-att {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: var(--space-3);
}
.sq-att-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: var(--space-2); }
.sq-att-title { font-weight: 600; font-size: var(--fs-3, 16px); }
.sq-att-meta { color: var(--text-muted); font-size: var(--fs-2, 13px); }

.sq-pt-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}
.sq-pt-cell {
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.025);
  padding: 6px 8px;
  border-radius: 6px;
}
.sq-pt-input {
  width: 100%;
  min-width: 0;
  padding: 6px 8px;
  font-weight: 600;
  text-align: right;
}
.sq-pt-val { font-weight: 600; min-width: 36px; text-align: right; }
.sq-dot {
  display: inline-block;
  width: 12px; height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}
.sq-dot-rossi  { background: #C62828; }
.sq-dot-gialli { background: #F9A825; }
.sq-dot-verdi  { background: #2E7D32; }
.sq-dot-blu    { background: #1565C0; }

@media (max-width: 640px) {
  .sq-card { grid-template-columns: 44px 1fr auto; gap: var(--space-2); padding: var(--space-2); }
  .sq-rank { font-size: 22px; }
  .sq-points { font-size: 24px; min-width: 48px; }
  .sq-pt-grid { grid-template-columns: repeat(2, 1fr); }
}

/* --- v2: sottosquadre + bottoni punti ------------------------------ */
.sq-toolbar-actions { display: flex; gap: var(--space-2); align-items: center; margin-left: auto; flex-wrap: wrap; }
.sq-points.is-neg { color: var(--err); }

/* Classifica: blocco sottosquadre */
.sq-subgroups {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.sq-sub {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 6px;
  padding: 4px 8px; border-radius: 6px;
  background: rgba(0,0,0,0.04);
  font-size: var(--fs-2, 13px);
}
.sq-sub-lbl { color: var(--text-muted); }
.sq-sub-val { font-weight: 700; }
.sq-sub-val.is-neg { color: var(--err); }

/* Attività: header cliccabile (toggle griglia) */
.sq-att-toggle {
  display: grid;
  grid-template-columns: auto 1fr auto auto;
  align-items: center;
  gap: var(--space-2);
  width: 100%;
  background: none; border: 0; padding: 0;
  text-align: left; cursor: pointer; font-family: inherit;
}
.sq-att-ico { font-size: 22px; line-height: 1; }
.sq-att-text { display: flex; flex-direction: column; }
.sq-att-text .sq-att-title { font-weight: 600; font-size: var(--fs-3, 16px); }
.sq-att-text .sq-att-meta { color: var(--text-muted); font-size: var(--fs-2, 13px); }
.sq-att-totali { display: flex; gap: 10px; flex-wrap: wrap; }
.sq-att-tot {
  display: inline-flex; align-items: center; gap: 4px;
  font-weight: 700;
  padding: 3px 8px; border-radius: 999px;
  background: rgba(0,0,0,0.04);
}
.sq-att-tot-v.is-neg { color: var(--err); }
.sq-att-chevron { color: var(--text-muted); font-size: 18px; line-height: 1; }
.sq-att-footer { display: flex; justify-content: flex-end; gap: var(--space-2); margin-top: var(--space-2); }
.btn.btn-sm { padding: 4px 10px; font-size: var(--fs-2, 13px); }

/* =====================================================================
   Vista "Punti del giorno" — card grandi Gioco/Laboratorio + wizard
   ===================================================================== */
.sq-section-h { font-size: var(--fs-4); font-weight: var(--fw-bold); margin: 0; }
.sq-classifica-head { margin-bottom: var(--space-3); }

/* Selettore settimana della classifica (S1/S2/S3/Generale) */
.sq-wk-btn {
  appearance: none;
  border: 1px solid var(--border, #d9dce1);
  background: var(--surface-2, #f4f5f7);
  color: var(--text, #1d2433);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: var(--fs-2, .9rem);
  font-weight: var(--fw-medium, 500);
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
}
.sq-wk-btn:hover { border-color: var(--brand-300, #64B5F6); }
.sq-wk-btn.is-active {
  background: var(--brand, #1E88E5);
  border-color: var(--brand, #1E88E5);
  color: #fff;
}
.sq-day-head { margin-bottom: var(--space-2); }
.sq-day-when { color: var(--brand); }

.sq-day-cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: var(--space-4);
  margin-top: var(--space-3);
}
.sq-day-card {
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--surface);
  box-shadow: var(--shadow-2);
  overflow: hidden;
}
.sq-day-card-gioco       { border-top: 5px solid #8E24AA; }
.sq-day-card-laboratorio { border-top: 5px solid #00897B; }
.sq-day-card-head {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-3) var(--space-2);
}
.sq-day-card-ico { font-size: 28px; line-height: 1; }
.sq-day-card-title { font-size: var(--fs-4); font-weight: var(--fw-bold); flex: 1; }

/* Tiles colorate per squadra con il totale del giorno */
.sq-tiles {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3);
}
.sq-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: var(--space-3) var(--space-1);
  border-radius: 12px;
  color: #fff;
  box-shadow: var(--shadow-1);
}
.sq-tile-rossi  { background: var(--team-rossi); }
.sq-tile-gialli { background: var(--team-gialli); color: #1f2328; }
.sq-tile-verdi  { background: var(--team-verdi); }
.sq-tile-blu    { background: var(--team-blu); }
.sq-tile-name { font-size: var(--fs-2); font-weight: var(--fw-semibold); text-transform: uppercase; letter-spacing: .03em; opacity: .95; }
.sq-tile-val { font-size: 30px; font-weight: 800; line-height: 1.05; }
.sq-tile-val.is-neg { opacity: .85; }

/* Riga gruppi: stato + azione inserisci/modifica */
.sq-grp-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: var(--space-2);
  padding: 0 var(--space-3) var(--space-3);
}
.sq-grp-btn {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  text-align: left;
  cursor: pointer;
  position: relative;
  transition: border-color .15s, box-shadow .15s, transform .05s;
}
.sq-grp-btn.is-readonly { cursor: default; }
button.sq-grp-btn:hover { border-color: var(--brand); box-shadow: var(--shadow-2); }
button.sq-grp-btn:active { transform: translateY(1px); }
.sq-grp-btn.is-done { background: var(--ok-soft); border-color: rgba(46,125,50,.4); }
.sq-grp-btn.is-todo { background: var(--surface-2); }
.sq-grp-name { font-weight: var(--fw-semibold); font-size: var(--fs-3); }
.sq-grp-sub  { font-size: var(--fs-2); color: var(--text-muted); }
.sq-grp-btn.is-done .sq-grp-sub { color: var(--ok); font-weight: var(--fw-semibold); }
.sq-grp-ico { position: absolute; top: 8px; right: 10px; font-size: 14px; }

.sq-day-foot { margin-top: var(--space-4); display: flex; justify-content: center; }

/* Wizard inserimento punti */
.wz-modal .wz-sub { margin: 4px 0 12px; }
.wz-h4 { margin: 14px 0 8px; font-size: var(--fs-3); font-weight: var(--fw-semibold); }
.wz-inputs { display: flex; flex-direction: column; gap: var(--space-2); }
.wz-row {
  display: grid;
  grid-template-columns: 20px 1fr 150px;
  align-items: center;
  gap: var(--space-2);
}
.wz-dot { width: 16px; height: 16px; border-radius: 50%; display: inline-block; }
.wz-name { font-weight: var(--fw-semibold); }
.wz-num { display: flex; align-items: center; gap: 6px; }
.wz-input { flex: 1; min-width: 0; text-align: right; font-size: var(--fs-4); font-weight: var(--fw-semibold); padding: 8px 10px; }
/* Pulsante segno +/− per i punti comportamento (necessario su mobile, dove il
   tastierino numerico non ha il meno) */
.wz-sign {
  flex: 0 0 auto;
  width: 40px; height: 40px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  font-size: 22px; font-weight: 800; line-height: 1;
  cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: background .12s, border-color .12s, color .12s;
}
.wz-sign.is-pos { color: var(--ok, #2E7D32); }
.wz-sign.is-neg { color: #fff; background: var(--err); border-color: var(--err); }
.wz-sign:active { transform: translateY(1px); }

@media (max-width: 480px) {
  .sq-tiles { grid-template-columns: repeat(2, 1fr); }
  .sq-grp-row { grid-template-columns: 1fr; }
  .sq-tile-val { font-size: 26px; }
}

/* Griglia 4×3 attività */
.sq-grid {
  margin-top: var(--space-3);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}
.sq-grid-head,
.sq-grid-row {
  display: grid;
  grid-template-columns: 120px repeat(3, 1fr);
}
.sq-grid-head {
  background: rgba(0,0,0,0.04);
  font-weight: 600;
  font-size: var(--fs-2, 13px);
  color: var(--text-muted);
}
.sq-grid-head > div { padding: 6px 10px; text-align: center; }
.sq-grid-row { border-top: 1px solid var(--border); }
.sq-grid-label {
  display: flex; align-items: center; gap: 8px;
  padding: 10px;
  font-weight: 600;
  background: rgba(0,0,0,0.02);
  border-right: 1px solid var(--border);
}
.sq-cell {
  display: flex; flex-direction: column; gap: 4px;
  padding: 10px;
  border-right: 1px solid var(--border);
  min-height: 84px;
}
.sq-cell:last-child { border-right: 0; }
.sq-cell-tot { font-size: 22px; font-weight: 800; line-height: 1; }
.sq-cell-tot.is-neg { color: var(--err); }
.sq-cell-ev { font-size: 11px; color: var(--text-muted); }
.sq-cell-actions {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: auto;
}
.sq-pt-btn {
  font-family: inherit;
  font-weight: 700; font-size: 12px;
  border: 1px solid var(--border);
  background: var(--surface);
  border-radius: 6px;
  padding: 4px 8px;
  cursor: pointer;
  min-width: 40px;
}
.sq-pt-btn.is-pos { color: #1b6e2c; border-color: #b6ddc1; background: #ebf7ee; }
.sq-pt-btn.is-pos:hover { background: #ddefdf; }
.sq-pt-btn.is-neg { color: #a01818; border-color: #efbdbd; background: #fbeeee; }
.sq-pt-btn.is-neg:hover { background: #f4dada; }
.sq-pt-btn.sq-pt-custom { color: var(--text-muted); }

/* Titoli e varianti per le griglie multiple (attività / comportamento / totale) */
.sq-grid-title {
  margin-top: var(--space-3);
  margin-bottom: 6px;
  font-weight: 700;
  font-size: var(--fs-3, 15px);
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.sq-grid-title-comp { color: #b8860b; }
.sq-grid-title-final { color: var(--brand-dark, #1f4ea0); }

.sq-grid-comp {
  background: rgba(255, 220, 100, 0.08);
}
.sq-grid-comp .sq-grid-head { background: rgba(255, 220, 100, 0.18); }
.sq-grid-comp .sq-grid-label { background: rgba(255, 220, 100, 0.10); }

.sq-grid-final {
  background: rgba(31, 78, 160, 0.04);
}
.sq-grid-final .sq-grid-head { background: rgba(31, 78, 160, 0.12); }
.sq-grid-final .sq-grid-label-final { background: rgba(31, 78, 160, 0.06); }
.sq-cell-final .sq-cell-tot { font-size: 26px; }
.text-small { font-size: 12px; font-weight: 500; }

@media (max-width: 640px) {
  .sq-att-toggle { grid-template-columns: auto 1fr auto; }
  .sq-att-totali { display: none; }
  .sq-grid-head, .sq-grid-row { grid-template-columns: 80px repeat(3, 1fr); }
  .sq-cell { padding: 8px 6px; min-height: 70px; }
  .sq-cell-tot { font-size: 18px; }
  .sq-subgroups { grid-template-columns: 1fr 1fr 1fr; }
}

/* =====================================================================
   PAGINA REGIA TABELLONE
   ===================================================================== */
.reg-toolbar { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-3); flex-wrap: wrap; }
.reg-toolbar-actions { display: flex; gap: var(--space-2); margin-left: auto; flex-wrap: wrap; }
.reg-stato { padding: var(--space-3); }
.reg-mode { font-weight: 700; font-size: var(--fs-4, 18px); margin: 0 0 4px; }
.reg-mode-standby { color: var(--text-muted); }
.reg-mode-cls     { color: #b8860b; }
.reg-mode-reveal  { color: var(--brand); }

.reg-grid {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
  margin-top: var(--space-2);
}
.reg-grid-head, .reg-grid-row {
  display: grid;
  grid-template-columns: 120px repeat(3, 1fr);
}
.reg-grid-head {
  background: rgba(0,0,0,0.04);
  font-weight: 600;
  font-size: var(--fs-2, 13px);
  color: var(--text-muted);
}
.reg-grid-head > div { padding: 6px 10px; text-align: center; }
.reg-grid-row { border-top: 1px solid var(--border); }
.reg-grid-label {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 10px; font-weight: 600;
  background: rgba(0,0,0,0.02);
  border-right: 1px solid var(--border);
}
.reg-cell {
  display: flex; flex-direction: column; gap: 6px;
  padding: 10px; border-right: 1px solid var(--border);
  min-height: 96px;
  transition: background 0.2s;
}
.reg-cell:last-child { border-right: 0; }
.reg-cell.is-revealed { background: rgba(255, 220, 100, 0.18); }
.reg-cell-tot { font-size: 22px; font-weight: 800; line-height: 1; }
.reg-cell-tot.is-neg { color: var(--err); }
.reg-cell-ev { font-size: 11px; color: var(--text-muted); }

@media (max-width: 640px) {
  .reg-grid-head, .reg-grid-row { grid-template-columns: 70px repeat(3, 1fr); }
  .reg-cell { padding: 8px 6px; min-height: 84px; }
  .reg-cell-tot { font-size: 18px; }
}

/* Titoli sopra le griglie regia */
.reg-grid-title {
  margin-top: var(--space-3);
  margin-bottom: 6px;
  font-weight: 700;
  font-size: var(--fs-3, 15px);
  display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap;
}
.reg-grid-title-comp { color: #b8860b; }
.reg-grid.reg-grid-comp { background: rgba(255, 220, 100, 0.06); }
.reg-grid.reg-grid-comp .reg-grid-head { background: rgba(255, 220, 100, 0.18); }
.reg-grid.reg-grid-comp .reg-grid-label { background: rgba(255, 220, 100, 0.10); }
.reg-grid.reg-grid-comp .reg-cell.is-revealed { background: rgba(255, 220, 100, 0.26); }

/* =====================================================================
   SCHEDA ISCRITTO (con editor medico)
   ===================================================================== */
.scheda { display: flex; flex-direction: column; gap: var(--space-4); }
.scheda-head { display: flex; flex-direction: column; gap: 4px; }
.scheda-head .btn { align-self: flex-start; }
.scheda-head h2 { margin: 4px 0 0; display: flex; align-items: center; gap: var(--space-2); flex-wrap: wrap; }

.scheda-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: var(--space-3);
}

/* Coppia chiave-valore "etichetta + valore" usata nella scheda */
.kv {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: var(--space-2);
  padding: 4px 0;
  border-bottom: 1px dashed var(--border-soft);
  font-size: var(--fs-2, 14px);
}
.kv:last-child { border-bottom: 0; }
.kv-k { color: var(--text-muted); }
.kv-v { word-break: break-word; }

.form-row { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--space-2); }
.form-row label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.form-row textarea.input { min-height: 56px; resize: vertical; }
.form-row label.check {
  display: flex; flex-direction: row; align-items: center; gap: var(--space-2);
  color: var(--text); font-size: var(--fs-2, 14px); font-weight: 400;
}
.form-row label.check input { transform: scale(1.2); margin: 0; }

.card-medico { border-left: 4px solid var(--ok); }
.card-medico.is-grave { border-left-color: var(--err); background: rgba(198,40,40,0.03); }

.scheda-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: var(--space-2) var(--space-3);
  display: flex;
  gap: var(--space-3);
  align-items: center;
  border-radius: 8px;
  box-shadow: 0 -2px 6px rgba(0,0,0,0.04);
  z-index: 5;
}
/* Mobile: la barra "Salva" deve stare sopra la bottom-nav fissa */
@media (max-width: 720px) {
  .scheda-actions {
    bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom, 0px));
  }
}

@media (max-width: 640px) {
  .kv { grid-template-columns: 100px 1fr; font-size: 13px; }
}

/* =====================================================================
   FOGLIO MEDICO
   ===================================================================== */
.med-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-3); flex-wrap: wrap;
  margin-bottom: var(--space-3);
}
.med-banner {
  background: #fff7e6;
  border: 1px solid #f0c47a;
  color: #6b4a0f;
  padding: var(--space-3);
  border-radius: 8px;
  margin-bottom: var(--space-3);
  font-size: var(--fs-2, 13px);
}
.med-head {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: var(--space-3);
  align-items: end;
  border-bottom: 2px solid var(--text);
  padding-bottom: var(--space-3);
  margin-bottom: var(--space-3);
}
.med-head h2 { margin: 0 0 4px; font-size: 22px; }
.med-head-stats {
  display: grid;
  grid-template-columns: repeat(4, auto);
  gap: var(--space-3);
}
.med-head-stats .stat {
  text-align: center;
  min-width: 60px;
  padding: 0;
}
.med-head-stats .stat-num { font-size: 24px; font-weight: 700; line-height: 1.1; }
.med-head-stats .stat-lbl { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; color: var(--text-muted); }

.med-table-wrap { overflow-x: auto; }
.med-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-2, 13px);
}
.med-table th, .med-table td {
  text-align: left;
  padding: 8px 10px;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}
.med-table th {
  background: var(--surface-alt);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .03em;
  color: var(--text-muted);
}
.med-table tr.is-grave td { background: rgba(198, 40, 40, 0.06); }
.med-table tr.is-grave .big-flag { color: var(--err); font-size: 18px; }
.med-table .big-flag { display:inline-block; width:18px; text-align:center; color: var(--text-faint); }
.med-table .who { display: flex; gap: 8px; align-items: flex-start; }
.med-table .name { font-weight: 600; }
.med-table .meta { color: var(--text-muted); font-size: 11px; margin-top: 2px; }
.med-table .col-name   { width: 24%; }
.med-table .col-cl     { width: 6%; }
.med-table .col-sq     { width: 9%; }
.med-table .col-pranzo { width: 11%; }
.med-table .col-allerg { width: 19%; }
.med-table .col-intoll { width: 17%; }
.med-table .col-note   { width: 14%; }
.med-footer { font-size: 11px; margin-top: var(--space-3); }

/* Banner risultati ricerca: appare sotto l'header quando c'è una query */
.med-filter-info {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  flex-wrap: wrap;
  background: var(--surface-2, var(--surface-alt));
  border: 1px solid var(--border-soft, var(--border));
  border-radius: 8px;
  padding: 8px 12px;
  margin-bottom: var(--space-3);
  font-size: var(--fs-2, 13px);
  color: var(--text-muted);
}
.med-filter-info strong { color: var(--text); }

/* Tablet: header impilato verticalmente */
@media (max-width: 900px) {
  .med-head {
    grid-template-columns: 1fr;
    align-items: stretch;
    gap: var(--space-2);
  }
  .med-head-stats {
    justify-content: start;
    gap: var(--space-2);
  }
}

/* Mobile: header compatto, tabella convertita in card-list */
@media (max-width: 720px) {
  .med-toolbar h1 { font-size: 18px; }
  .med-banner { font-size: 12px; padding: var(--space-2); }

  .med-head { padding-bottom: var(--space-2); margin-bottom: var(--space-2); }
  .med-head h2 { font-size: 17px; line-height: 1.25; }
  .med-head-title p { font-size: 12px; }
  .med-head-stats {
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    width: 100%;
  }
  .med-head-stats .stat {
    min-width: 0;
    padding: 6px 4px;
    background: var(--surface-2, var(--surface-alt));
    border-radius: 6px;
  }
  .med-head-stats .stat-num { font-size: 18px; }
  .med-head-stats .stat-lbl { font-size: 10px; }

  /* IMPORTANTE: override delle larghezze "col-*" ereditate dal desktop
     (.med-table .col-cl { width: 6% } ecc.) altrimenti su mobile i <td>
     restano larghi pochi pixel e i valori vengono spezzati a 1 carattere. */
  .med-table td.col-name,
  .med-table td.col-cl,
  .med-table td.col-sq,
  .med-table td.col-pranzo,
  .med-table td.col-allerg,
  .med-table td.col-intoll,
  .med-table td.col-note {
    width: 100%;
  }

  /* Convertiamo la tabella in lista di card con layout stacked
     (label sopra, valore sotto): è il pattern più affidabile su mobile
     e funziona anche con valori lunghi tipo "DIABETE (GLUTEN FREE)". */
  .med-table-wrap { overflow-x: visible; width: 100%; }
  .med-table {
    display: block;
    width: 100%;
    box-sizing: border-box;
    font-size: 13px;
    border-collapse: separate;
    border-spacing: 0;
  }
  .med-table thead { display: none; }
  .med-table tbody { display: block; width: 100%; }
  .med-table tr {
    display: block;
    width: 100%;
    box-sizing: border-box;
    border: 1px solid var(--border);
    border-radius: 10px;
    margin-bottom: var(--space-2);
    background: var(--surface);
    padding: 12px 14px;
  }
  .med-table tr.is-grave {
    border-color: var(--err);
    border-left-width: 4px;
    background: rgba(198, 40, 40, 0.05);
  }
  /* Su mobile rimuoviamo il bg rosso sui td gravi: c'è già sul tr */
  .med-table tr.is-grave td { background: transparent; }

  .med-table td {
    display: block;
    width: 100%;
    box-sizing: border-box;
    border-bottom: 1px dashed var(--border-soft, var(--border));
    padding: 8px 0;
    overflow-wrap: anywhere;
    word-break: normal;
  }
  .med-table td:first-child { padding-top: 0; }
  .med-table td:last-child { border-bottom: 0; padding-bottom: 0; }
  .med-table td::before {
    content: attr(data-label);
    display: block;
    font-size: 10px;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: .05em;
    font-weight: 600;
    margin-bottom: 3px;
  }
  .med-table .med-val {
    display: block;
    font-size: 14px;
    line-height: 1.35;
    overflow-wrap: anywhere;
    word-break: normal;
  }

  /* La cella "Bambino" è in evidenza: blocco intero, label nascosta */
  .med-table td.col-name {
    border-bottom: 1px solid var(--border);
    margin-bottom: 8px;
    padding-bottom: 10px;
  }
  .med-table td.col-name::before { display: none; }
  .med-table .who { display: flex; gap: 10px; align-items: flex-start; }
  .med-table .name { font-size: 16px; font-weight: 700; overflow-wrap: anywhere; }
  .med-table .meta { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; margin-top: 2px; }
  .med-table tr.is-grave .big-flag { font-size: 22px; line-height: 1; }

  /* Cella note vuota: nascondi se non c'è contenuto utile */
  .med-table td.col-note.is-empty { display: none; }
}

/* =====================================================================
   STAMPA: layout pulito, nessuna toolbar, nessun banner web
   ===================================================================== */
/* =====================================================================
   SCHEDA ISCRITTO — genitori, contatti, WhatsApp, storico
   ===================================================================== */
.genitori-list { display: flex; flex-direction: column; gap: var(--space-2); }
.genitore-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2);
  padding: var(--space-2);
  background: var(--surface-2);
  border-radius: var(--radius-1);
  border: 1px solid var(--border-soft);
  flex-wrap: wrap;
}
.genitore-info { display: flex; flex-direction: column; gap: 2px; min-width: 0; flex: 1 1 180px; }
.genitore-ruolo {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-muted); font-weight: var(--fw-medium);
}
.genitore-nome { font-weight: var(--fw-semibold); font-size: var(--fs-3); }
.genitore-tel  { font-size: var(--fs-2); }
.genitore-actions { display: flex; gap: var(--space-1); flex-wrap: wrap; }

.btn-sm {
  font-size: var(--fs-2);
  padding: 4px 10px;
  min-height: 32px;
  border-radius: var(--radius-1);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
}
.btn-wa {
  background: #25D366;
  color: #fff;
  border: 1px solid #1ebc59;
}
.btn-wa:hover { filter: brightness(1.05); }

/* Storico presenze/uscite */
.card-storico { grid-column: 1 / -1; }
.storico-stats {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
  margin-bottom: var(--space-3);
}
.storico-stat {
  display: flex; flex-direction: column; align-items: center;
  padding: var(--space-2);
  background: var(--surface-2);
  border-radius: var(--radius-1);
  border: 1px solid var(--border-soft);
}
.storico-stat-n {
  font-size: var(--fs-5);
  font-weight: var(--fw-bold);
  color: var(--brand-dark);
  line-height: 1.1;
}
.storico-stat-lbl {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}

.storico-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  max-height: 480px;
  overflow-y: auto;
}
.storico-row {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: var(--space-2);
  padding: var(--space-2);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-1);
  background: var(--surface);
}
.storico-row.is-presente { border-left: 3px solid var(--ok); }
.storico-row.is-assente  { border-left: 3px solid var(--err); background: var(--err-soft); }
.storico-row.is-nd       { border-left: 3px solid var(--border-strong); }
.storico-data { display: flex; flex-direction: column; gap: 2px; }
.storico-data-gg { font-weight: var(--fw-semibold); font-size: var(--fs-2); }
.storico-data-sett {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
}
.storico-body { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.storico-stato { font-size: var(--fs-2); font-weight: var(--fw-medium); }
.storico-det { font-size: var(--fs-2); }
.storico-note {
  font-size: var(--fs-2);
  background: var(--warn-soft);
  color: #6b4a0f;
  padding: 4px 8px;
  border-radius: var(--radius-1);
  margin-top: 2px;
}

@media (max-width: 640px) {
  .storico-stats { grid-template-columns: repeat(2, 1fr); }
  .storico-row   { grid-template-columns: 90px 1fr; }
  .genitore-actions { width: 100%; }
}

@media print {
  .no-print, .app-header, .app-nav { display: none !important; }
  body { background: #fff !important; }
  .app-main { padding: 0 !important; }
  .med-head { page-break-inside: avoid; }
  .med-table { font-size: 11px; }
  .med-table th { background: #eee !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .med-table tr { page-break-inside: avoid; }
  .med-table tr.is-grave td {
    background: #fde7e7 !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .badge { border: 1px solid #999; padding: 1px 4px; }
  /* Scheda medica: A4 VERTICALE (poche colonne, più leggibile). */
  @page { size: A4 portrait; margin: 12mm 10mm; }
}

/* =====================================================================
   CRUSCOTTO (admin)
   ===================================================================== */
.cr-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2); flex-wrap: wrap;
}
.cr-dayline { font-weight: var(--fw-bold, 700); margin: var(--space-3) 0 0; }
.cr-h {
  font-size: var(--fs-3, 1.05rem); font-weight: var(--fw-bold, 700);
  margin: var(--space-4) 0 var(--space-2);
}
.cr-cards {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--space-2);
}
@media (max-width: 720px) { .cr-cards { grid-template-columns: repeat(2, 1fr); } }
.cr-card {
  border: 1px solid var(--border, #e3e6ea); border-radius: var(--radius-2, 12px);
  padding: 14px 12px; text-align: center; background: var(--surface, #fff);
  border-left-width: 5px;
}
.cr-card-val { font-size: 2rem; font-weight: var(--fw-bold, 800); line-height: 1.1; }
.cr-card-lbl { font-size: var(--fs-1, .8rem); color: var(--text-muted, #5b6470); margin-top: 4px; }
.cr-card-sub { font-size: .72rem; color: var(--text-muted, #8a95a0); margin-top: 2px; }
.cr-ok     { border-left-color: var(--ok, #2E7D32); }
.cr-ok     .cr-card-val { color: var(--ok, #2E7D32); }
.cr-warn   { border-left-color: #F9A825; }
.cr-todo   { border-left-color: var(--brand, #1E88E5); }
.cr-todo   .cr-card-val { color: var(--brand, #1E88E5); }
.cr-info   { border-left-color: #00897B; }
.cr-danger { border-left-color: #C62828; }
.cr-danger .cr-card-val { color: #C62828; }
.cr-muted  { border-left-color: var(--border, #d9dce1); }

/* Mini-grafico andamento */
.cr-chart {
  display: flex; align-items: flex-end; gap: 8px; height: 160px;
  padding: 10px 4px 0; border: 1px solid var(--border, #e3e6ea);
  border-radius: var(--radius-2, 12px); background: var(--surface, #fff);
}
.cr-bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; height: 100%; justify-content: flex-end; }
.cr-bar-wrap { width: 100%; flex: 1; display: flex; align-items: flex-end; }
.cr-bar { width: 70%; margin: 0 auto; background: var(--brand-300, #64B5F6); border-radius: 4px 4px 0 0; transition: height .3s; }
.cr-bar-col.is-active .cr-bar { background: var(--brand, #1E88E5); }
.cr-bar-n { font-size: var(--fs-1, .8rem); font-weight: var(--fw-bold, 700); margin-top: 4px; }
.cr-bar-lbl { font-size: .72rem; color: var(--text-muted, #5b6470); }

/* Classifica sintetica */
.cr-cls { display: flex; flex-direction: column; gap: 6px; }
.cr-cls-row { display: flex; align-items: center; gap: 8px; }
.cr-cls-rank { width: 28px; text-align: center; }
.cr-cls-name { width: 70px; font-weight: var(--fw-medium, 600); }
.cr-cls-bar { flex: 1; height: 14px; background: var(--surface-2, #f0f1f3); border-radius: 999px; overflow: hidden; }
.cr-cls-fill { display: block; height: 100%; border-radius: 999px; }
.cr-cls-pts { width: 56px; text-align: right; font-weight: var(--fw-bold, 700); }
.cr-cls-pts.is-neg { color: #C62828; }

/* =====================================================================
   ATTIVITÀ STAFF (admin)
   ===================================================================== */
.at-toolbar { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); flex-wrap: wrap; }
.at-table-wrap { overflow-x: auto; }
.at-table { width: 100%; }
.at-table .num { text-align: right; }
.at-filtri { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin: var(--space-2) 0; }
.at-seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.at-fbtn {
  appearance: none; border: 1px solid var(--border, #d9dce1); background: var(--surface, #fff);
  color: var(--text, #1d2433); border-radius: 8px; padding: 5px 11px; font-size: var(--fs-1, .82rem); cursor: pointer;
}
.at-fbtn.is-active { background: var(--brand-soft, #E3F2FD); border-color: var(--brand-300, #64B5F6); color: var(--brand-dark, #1565C0); font-weight: 700; }

.at-feed { display: flex; flex-direction: column; gap: 6px; }
.at-card { border: 1px solid var(--border, #e3e6ea); border-radius: var(--radius-2, 12px); padding: 9px 12px; background: var(--surface, #fff); }
.at-card-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.at-badge { font-size: .68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em; padding: 2px 8px; border-radius: 6px; color: #fff; background: #90A4AE; }
.at-punti { background: #6A1B9A; }
.at-presenza { background: #1E88E5; }
.at-iscritto { background: #00897B; }
.at-utente { background: #C62828; }
.at-attivita { background: #F9A825; color: #3a2f00; }
.at-who { font-weight: var(--fw-medium, 600); }
.at-ts { font-size: var(--fs-1, .8rem); color: var(--text-muted, #5b6470); flex: 1; }
.at-corr.btn-sm { padding: 3px 8px; }
.at-desc { margin-top: 4px; word-break: break-word; }

/* =====================================================================
   ELENCHI / STAMPE (admin)
   ===================================================================== */
.el-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2); flex-wrap: wrap;
}
.el-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--space-3) 0 var(--space-2); }
.el-tab {
  appearance: none; border: 1px solid var(--border, #d9dce1);
  background: var(--surface-2, #f4f5f7); color: var(--text, #1d2433);
  border-radius: 999px; padding: 6px 14px; font-size: var(--fs-2, .9rem);
  font-weight: var(--fw-medium, 600); cursor: pointer;
}
.el-tab.is-active { background: var(--brand, #1E88E5); border-color: var(--brand, #1E88E5); color: #fff; }

.el-filtri { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: var(--space-2); }
.el-seg { display: inline-flex; flex-wrap: wrap; gap: 4px; }
.el-fbtn {
  appearance: none; border: 1px solid var(--border, #d9dce1);
  background: var(--surface, #fff); color: var(--text, #1d2433);
  border-radius: 8px; padding: 5px 11px; font-size: var(--fs-1, .82rem); cursor: pointer;
}
.el-fbtn.is-active { background: var(--brand-soft, #E3F2FD); border-color: var(--brand-300, #64B5F6); color: var(--brand-dark, #1565C0); font-weight: 700; }

.el-head { margin: var(--space-3) 0 var(--space-2); }
.el-h { font-size: var(--fs-4, 1.15rem); font-weight: var(--fw-bold, 700); margin: 0; }
.el-table-wrap { overflow-x: auto; }
.el-table { width: 100%; }

/* =====================================================================
   LOG ERRORI (admin)
   ===================================================================== */
.lg-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2); flex-wrap: wrap;
}
.lg-filtri { display: flex; flex-wrap: wrap; gap: 6px; margin: var(--space-3) 0 var(--space-2); }
.lg-fbtn {
  appearance: none; border: 1px solid var(--border, #d9dce1);
  background: var(--surface-2, #f4f5f7); color: var(--text, #1d2433);
  border-radius: 999px; padding: 5px 12px; font-size: var(--fs-1, .82rem); cursor: pointer;
}
.lg-fbtn.is-active { background: var(--brand, #1E88E5); border-color: var(--brand, #1E88E5); color: #fff; }

.lg-summary { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: var(--space-2); }
.lg-pill {
  font-size: var(--fs-1, .78rem); padding: 3px 10px; border-radius: 999px;
  background: var(--surface-2, #eef0f2); color: var(--text-muted, #5b6470);
}
.lg-pill-new { background: var(--brand-soft, #E3F2FD); color: var(--brand-dark, #1565C0); font-weight: 700; }
.lg-pill-critical { background: #FCE4EC; color: #AD1457; }
.lg-pill-error { background: #FFEBEE; color: #C62828; }
.lg-pill-warning { background: #FFF8E1; color: #F57F17; }

.lg-list { display: flex; flex-direction: column; gap: 8px; }
.lg-card {
  border: 1px solid var(--border, #e3e6ea); border-radius: var(--radius-2, 12px);
  padding: 10px 12px; background: var(--surface, #fff); border-left-width: 5px;
}
.lg-critical { border-left-color: #AD1457; }
.lg-error    { border-left-color: #C62828; }
.lg-warning  { border-left-color: #F9A825; }
.lg-info, .lg-debug { border-left-color: var(--border, #d9dce1); }
.lg-card.is-new { background: var(--brand-soft, #f3f9ff); }

.lg-card-top { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.lg-badge {
  font-size: .7rem; font-weight: 700; text-transform: uppercase; letter-spacing: .03em;
  padding: 2px 8px; border-radius: 6px; color: #fff;
}
.lg-badge-critical { background: #AD1457; }
.lg-badge-error    { background: #C62828; }
.lg-badge-warning  { background: #F9A825; color: #3a2f00; }
.lg-badge-info, .lg-badge-debug { background: #90A4AE; }
.lg-ts { font-size: var(--fs-1, .8rem); color: var(--text-muted, #5b6470); flex: 1; }
.lg-read { font-size: var(--fs-1, .78rem); color: var(--text-muted, #8a95a0); }
.lg-seen.btn-sm { padding: 3px 8px; }
.lg-msg { font-weight: var(--fw-medium, 600); margin-top: 6px; word-break: break-word; }
.lg-ep { font-size: var(--fs-1, .8rem); color: var(--text-muted, #5b6470); margin-top: 2px; font-family: monospace; }
.lg-det { margin-top: 6px; }
.lg-det summary { cursor: pointer; font-size: var(--fs-1, .82rem); color: var(--brand-dark, #1565C0); }
.lg-meta { font-size: var(--fs-1, .78rem); color: var(--text-muted, #5b6470); margin: 6px 0; word-break: break-all; }
.lg-trace {
  background: var(--surface-2, #f6f7f9); border-radius: 8px; padding: 8px 10px; margin: 6px 0 0;
  font-size: 11px; overflow-x: auto; white-space: pre-wrap; word-break: break-word;
  max-height: 240px;
}

/* =====================================================================
   PAGINA UTENTI (admin)
   ===================================================================== */
.ut-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--space-2); flex-wrap: wrap; margin-bottom: var(--space-2);
}
.ut-table-wrap { overflow-x: auto; margin-top: var(--space-3); }
.ut-table { width: 100%; border-collapse: collapse; font-size: var(--fs-2, .92rem); }
.ut-table th, .ut-table td {
  text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border, #e3e6ea);
  vertical-align: middle;
}
.ut-table thead th {
  font-weight: var(--fw-bold, 700); color: var(--text-muted, #5b6470);
  font-size: var(--fs-1, .8rem); text-transform: uppercase; letter-spacing: .03em;
}
.ut-center { text-align: center; }
.ut-row-off { opacity: .55; }
.ut-name { font-weight: var(--fw-medium, 600); }
.ut-you { color: var(--brand, #1E88E5); font-weight: 400; font-size: .85em; }
.ut-user { color: var(--text-muted, #5b6470); font-size: var(--fs-1, .8rem); }
.ut-role { min-width: 130px; padding: 4px 8px; }

.ut-caps { display: flex; flex-wrap: wrap; gap: 6px 12px; }
.ut-cap {
  display: inline-flex; align-items: center; gap: 5px; cursor: pointer;
  font-size: var(--fs-1, .82rem); white-space: nowrap;
}
.ut-cap input[disabled] { cursor: not-allowed; }
.ut-cap input[disabled] + span { color: var(--text-muted, #8a95a0); }

.ut-actions { white-space: nowrap; }
.ut-actions .btn-sm { padding: 4px 8px; }
.ut-del:not([disabled]):hover { color: #C62828; }

/* Interruttore attivo/sospeso */
.ut-switch { position: relative; display: inline-block; width: 42px; height: 24px; }
.ut-switch input { opacity: 0; width: 0; height: 0; }
.ut-slider {
  position: absolute; inset: 0; cursor: pointer; border-radius: 999px;
  background: var(--surface-3, #c7ccd3); transition: background .15s;
}
.ut-slider::before {
  content: ""; position: absolute; height: 18px; width: 18px; left: 3px; top: 3px;
  background: #fff; border-radius: 50%; transition: transform .15s;
}
.ut-switch input:checked + .ut-slider { background: var(--ok, #2E7D32); }
.ut-switch input:checked + .ut-slider::before { transform: translateX(18px); }
.ut-switch input:disabled + .ut-slider { opacity: .6; cursor: not-allowed; }

/* Form modale utenti */
.ut-form { display: flex; flex-direction: column; gap: var(--space-2); margin: var(--space-2) 0; }
.ut-field { display: flex; flex-direction: column; gap: 4px; }
.ut-field > span { font-size: var(--fs-1, .82rem); font-weight: var(--fw-medium, 600); color: var(--text-muted, #5b6470); }
