:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #d97706;
  --accent-ink: #ffffff;
  --header: #1e293b;
  --header-ink: #f8fafc;
  --danger: #dc2626;
  --success: #16a34a;
  --late: #d97706;
  --radius: 14px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .08), 0 1px 2px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}
a { color: inherit; text-decoration: none; }

/* ---------- App shell ---------- */
.app-header {
  position: sticky; top: 0; z-index: 30;
  height: 56px; display: flex; align-items: center; gap: 12px;
  padding: 0 14px; background: var(--header); color: var(--header-ink);
  box-shadow: var(--shadow);
}
.app-header h1 {
  font-size: 17px; font-weight: 600; margin: 0; letter-spacing: .2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
/* Hamburger e freccia stanno appaiati: il gap del header li allontanerebbe
   troppo e ruberebbe spazio al titolo. */
.app-header .icon-btn + .icon-btn { margin-left: -8px; }
.app-header .club-logo { width: 30px; height: 30px; border-radius: 8px; object-fit: cover; background: #334155; }
.icon-btn {
  appearance: none; border: 0; background: transparent; color: inherit;
  width: 40px; height: 40px; border-radius: 10px; font-size: 22px; line-height: 1;
  display: grid; place-items: center; cursor: pointer;
}
.icon-btn:active { background: rgba(255,255,255,.12); }
.header-spacer { flex: 1; }

/* ---------- Drawer ---------- */
.drawer {
  position: fixed; top: 0; left: 0; bottom: 0; width: 78%; max-width: 300px; z-index: 50;
  background: var(--header); color: var(--header-ink);
  transform: translateX(-100%); transition: transform .22s ease;
  display: flex; flex-direction: column; padding: 18px 0;
}
.drawer-brand { padding: 6px 20px 18px; font-size: 20px; font-weight: 700; display: flex; align-items: center; gap: 10px; }
.drawer a {
  display: flex; align-items: center; gap: 14px; padding: 14px 20px; font-size: 16px;
  color: #cbd5e1; border-left: 3px solid transparent;
}
.drawer a .ic { font-size: 20px; width: 24px; text-align: center; }
.drawer a.active { color: #fff; background: rgba(217,119,6,.16); border-left-color: var(--accent); }
.drawer a:active { background: rgba(255,255,255,.08); }
.drawer-footer { margin-top: auto; padding: 12px 20px 4px; border-top: 1px solid rgba(255,255,255,.08); }
.drawer-backdrop {
  position: fixed; inset: 0; z-index: 40; background: rgba(15,23,42,.5);
  opacity: 0; visibility: hidden; transition: opacity .2s ease;
}
body.menu-open .drawer { transform: translateX(0); }
body.menu-open .drawer-backdrop { opacity: 1; visibility: visible; }

/* ---------- Layout ---------- */
.container { max-width: 720px; margin: 0 auto; padding: 16px 14px 96px; }
.page-title { font-size: 22px; font-weight: 700; margin: 4px 2px 16px; }
.section-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 22px 4px 8px; font-weight: 600; }

/* ---------- Cards / list ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card + .card { margin-top: 12px; }
.card-pad { padding: 16px; }

.list { display: flex; flex-direction: column; gap: 10px; }
.list-item {
  display: flex; align-items: center; gap: 14px; padding: 14px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.list-item:active { background: var(--surface-2); }
.list-item .grow { flex: 1; min-width: 0; }
.list-item .title { font-weight: 600; font-size: 16px; }
.list-item .sub { color: var(--muted); font-size: 13px; margin-top: 2px; }
.list-item .chev { color: var(--muted); font-size: 20px; }

.avatar {
  width: 46px; height: 46px; border-radius: 50%; object-fit: cover; flex-shrink: 0;
  background: var(--surface-2); display: grid; place-items: center; color: var(--muted);
  font-weight: 700; border: 1px solid var(--border);
}

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.badge.role { background: #eef2ff; color: #4338ca; border-color: #e0e7ff; }
.badge.match { background: #ecfeff; color: #0e7490; border-color: #cffafe; }
.badge.training { background: #f0fdf4; color: #15803d; border-color: #dcfce7; }
.badge.present { background: #f0fdf4; color: #15803d; border-color: #dcfce7; }
.badge.absent { background: #fef2f2; color: #b91c1c; border-color: #fee2e2; }
.badge.late { background: #fffbeb; color: #b45309; border-color: #fef3c7; }

/* ---------- Buttons ---------- */
.btn {
  appearance: none; cursor: pointer; font: inherit; font-weight: 600;
  padding: 12px 18px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text); display: inline-flex; align-items: center; justify-content: center; gap: 8px;
}
.btn:active { transform: translateY(1px); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 8px 12px; font-size: 14px; }

/* Floating add button */
.fab {
  position: fixed; right: 18px; bottom: 22px; z-index: 20;
  width: 58px; height: 58px; border-radius: 50%; background: var(--accent); color: #fff;
  border: 0; font-size: 30px; box-shadow: 0 6px 16px rgba(217,119,6,.4); display: grid; place-items: center;
}

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.field .hint { color: var(--muted); font-size: 12px; margin-top: 4px; }
input[type=text], input[type=password], input[type=date], input[type=time], input[type=tel], input[type=number], input[type=file], select, textarea {
  width: 100%; padding: 12px 14px; font: inherit; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
textarea { min-height: 84px; resize: vertical; }
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.check-pill { display: inline-flex; align-items: center; gap: 8px; padding: 10px 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-actions { display: flex; gap: 10px; margin-top: 22px; }

/* ---------- Flash / errors ---------- */
.flash { padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 600; }
.flash.ok { background: #f0fdf4; color: #15803d; border: 1px solid #dcfce7; }
.flash.error { background: #fef2f2; color: #b91c1c; border: 1px solid #fee2e2; }
.errors { background: #fef2f2; color: #b91c1c; border: 1px solid #fee2e2; padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-size: 14px; }
.errors ul { margin: 6px 0 0; padding-left: 18px; }

/* ---------- Empty state ---------- */
.empty { text-align: center; color: var(--muted); padding: 48px 20px; }
.empty .em { font-size: 42px; }
.empty p { margin: 10px 0 0; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100dvh; display: grid; place-items: center; padding: 24px; background: var(--header); }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: 20px; padding: 28px 24px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.login-logo { text-align: center; font-size: 40px; }
.login-card h1 { text-align: center; font-size: 22px; margin: 8px 0 22px; }

/* ---------- Misc ---------- */
.muted { color: var(--muted); }
.stat-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-align: center; }
.stat .num { font-size: 24px; font-weight: 700; }
.stat .lbl { font-size: 12px; color: var(--muted); margin-top: 2px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }

/* ---------- Segmented presence control (P / R / A) ---------- */
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 10px; overflow: hidden; flex-shrink: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg label { padding: 9px 14px; font-weight: 700; font-size: 14px; cursor: pointer; background: var(--surface); color: var(--muted); border-left: 1px solid var(--border); }
.seg label:first-of-type { border-left: 0; }
.seg input:checked + label.p { background: var(--success); color: #fff; }
.seg input:checked + label.r { background: var(--late); color: #fff; }
.seg input:checked + label.a { background: var(--danger); color: #fff; }

.draft-note { font-size: 12px; color: var(--muted); text-align: center; margin-top: 10px; }
.save-bar { position: sticky; bottom: 0; padding: 12px 0 14px; background: linear-gradient(to top, var(--bg) 70%, transparent); margin-top: 6px; }

/* ---------- Statistiche ---------- */
.season-picker { margin: 4px 0 12px; }
.season-picker select { font-weight: 600; }
.tabs {
  display: flex; gap: 6px; overflow-x: auto; margin: 0 -14px 4px; padding: 0 14px 4px;
  scrollbar-width: none; -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: 0 0 auto; padding: 9px 14px; border-radius: 999px; font-size: 14px; font-weight: 600;
  background: var(--surface); border: 1px solid var(--border); color: var(--muted); white-space: nowrap;
}
.tabs a.active { background: var(--header); border-color: var(--header); color: var(--header-ink); }
/* Filtri a pulsante: il selezionato è pieno e scuro, così si capisce a colpo
   d'occhio quale dei due è attivo anche di sfuggita a bordo campo. */
.toggle-row { display: flex; gap: 10px; margin: 14px 0 4px; }
.toggle {
  flex: 1; text-align: center; padding: 13px 12px; font-size: 15px; font-weight: 600;
  border: 1px solid var(--border); border-radius: 12px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
.toggle:active { transform: translateY(1px); }
.toggle.active {
  background: var(--header); border-color: var(--header); color: var(--header-ink);
  box-shadow: 0 2px 10px rgba(15, 23, 42, .28);
}
.bar { height: 6px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); margin-top: 7px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }
.rank-value { font-size: 20px; font-weight: 700; flex-shrink: 0; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th, .table td { padding: 9px 12px; text-align: right; }
.table th:first-child, .table td:first-child { text-align: left; }
.table thead th { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; }
.table tbody tr { border-top: 1px solid var(--border); }
.table td.up { color: var(--success); font-weight: 600; }
.table td.down { color: var(--danger); font-weight: 600; }
.timeline-item .when { font-size: 12px; color: var(--muted); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* ---------- Messaggistica ---------- */
.code-block {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px;
  padding: 10px 12px; font-size: 12px; overflow-x: auto; margin: 10px 0;
}
.link-field {
  width: 100%; margin-top: 6px; font-size: 12px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}
code { background: var(--surface-2); border-radius: 6px; padding: 1px 5px; font-size: 12px; }

/* ---------- Gruppi per ruolo ---------- */
.role-group { margin-bottom: 18px; }
.role-group-head {
  font-size: 12px; text-transform: uppercase; letter-spacing: .06em; font-weight: 700;
  color: var(--muted); padding: 0 4px 8px;
}
.role-group .card + .card { margin-top: 8px; }

/* ---------- Agenda ---------- */
/* L'header è sticky: l'ancora deve fermarsi sotto, non sparirci dietro. */
#ora { scroll-margin-top: 68px; }
.list-item.is-current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), var(--shadow); }
.list-item.is-past { opacity: .62; }

/* Riga agenda: il link all'evento occupa tutta la riga, il pulsante mappa gli
   sta accanto come elemento separato (un <a> dentro un <a> spezzerebbe la riga). */
.list-item > .row-link {
  display: flex; align-items: center; gap: 14px; flex: 1; min-width: 0; color: inherit;
}
.map-btn {
  flex-shrink: 0; width: 44px; height: 44px; border-radius: 12px; font-size: 20px;
  display: grid; place-items: center;
  background: var(--surface-2); border: 1px solid var(--border);
}
.map-btn:active { background: var(--border); }

/* ---------- WhatsApp: QR di collegamento ---------- */
.wa-qr {
  display: block; width: 100%; max-width: 280px; margin: 0 auto;
  aspect-ratio: 1; border-radius: 12px; background: #fff; padding: 8px;
  box-shadow: var(--shadow);
}
