:root {
  --bg: #f2f5f9;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #e1e6ed;
  --text: #17212e;
  --muted: #66727f;
  --primary: #0b6bcb;
  --primary-ink: #ffffff;
  --primary-soft: #e3effb;
  --accent: #ff7a1a;
  --danger: #d23b3b;
  --danger-soft: #fdeaea;
  --ok: #1f9d55;
  --ok-soft: #e3f5ea;
  --warn: #b86e00;
  --warn-soft: #fff3df;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 2px 8px rgba(16, 24, 40, .05);
  --radius: 14px;
  --sp-triathlon: #7a4fd6;
  --sp-duathlon: #c2410c;
  --sp-aquathlon: #0891b2;
  --sp-swimrun: #0d9488;
  --sp-natation: #0b6bcb;
  --sp-velo: #ea7a11;
  --sp-course: #1f9d55;
  --sp-trail: #8b5e34;
  --sp-sauvetage: #dc2626;
  --sp-athletisme: #b45309;
  --sp-judo: #4338ca;
  --sp-karate: #be123c;
  --sp-taekwondo: #0f766e;
  --sp-lutte: #9a3412;
  --sp-escrime: #475569;
  --sp-gymnastique: #c026d3;
  --sp-tennis: #4d7c0f;
  --sp-badminton: #0369a1;
  --sp-aviron: #0e7490;
  --sp-autre: #64748b;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e141b;
    --surface: #17202a;
    --surface-2: #1d2833;
    --border: #2a3744;
    --text: #e8eef4;
    --muted: #93a1af;
    --primary: #4ea3f5;
    --primary-ink: #07121d;
    --primary-soft: #16324d;
    --danger-soft: #3a1c1f;
    --ok-soft: #133024;
    --warn-soft: #3a2a10;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.45;
  -webkit-tap-highlight-color: transparent;
  padding-bottom: calc(72px + env(safe-area-inset-bottom));
}
body.no-nav { padding-bottom: 0; }
a { color: var(--primary); }
h1, h2, h3 { line-height: 1.2; margin: 0 0 .5em; }
h1 { font-size: 1.45rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
img { max-width: 100%; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.hidden { display: none !important; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.center { text-align: center; }

/* ---------- Shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
}
.topbar-inner { max-width: 900px; margin: 0 auto; display: flex; align-items: center; gap: 10px; }
.brand { font-weight: 800; color: var(--primary); text-decoration: none; font-size: 1.1rem; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.brand img { width: 28px; height: 28px; border-radius: 8px; }
.club-select { flex: 1; min-width: 0; max-width: 280px; }
@media (max-width: 520px) { .hide-sm { display: none; } }
.icon-btn {
  position: relative; border: 0; background: transparent; color: var(--text);
  width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; cursor: pointer; text-decoration: none; flex: none;
}
.icon-btn:hover { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }
.badge-dot {
  position: absolute; top: 4px; right: 3px; background: var(--danger); color: #fff;
  font-size: 10px; font-weight: 700; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px;
}
main { max-width: 900px; margin: 0 auto; padding: 14px 12px 24px; }
.bottomnav {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  background: var(--surface); border-top: 1px solid var(--border);
  display: flex; justify-content: space-around; padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
}
.bottomnav a {
  flex: 1; max-width: 120px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600; padding: 6px 0; border-radius: 10px;
}
.bottomnav a svg { width: 23px; height: 23px; }
.bottomnav a.active { color: var(--primary); }
.bottomnav a.fab span.fab-circle {
  background: var(--primary); color: var(--primary-ink); width: 44px; height: 44px; border-radius: 50%;
  display: grid; place-items: center; margin-top: -18px; box-shadow: 0 4px 12px rgba(11, 107, 203, .35);
}
.offline-banner { background: var(--warn-soft); color: var(--warn); text-align: center; font-size: .85rem; padding: 6px; }

/* ---------- Composants ---------- */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px; }
.card + .card { margin-top: 12px; }
.card.flat { box-shadow: none; border: 1px solid var(--border); }
.btn {
  appearance: none; border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-weight: 600; padding: 9px 14px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none; min-height: 40px;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, var(--border)); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.small { padding: 5px 10px; min-height: 32px; font-size: .85rem; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; }

label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 4px; }
.field { margin-bottom: 14px; }
.field .hint { font-weight: 400; color: var(--muted); font-size: .8rem; margin-top: 4px; }
input:not([type]), input[type=text], input[type=email], input[type=password], input[type=number], input[type=url], input[type=date],
input[type=datetime-local], input[type=search], select, textarea {
  width: 100%; font: inherit; color: var(--text); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; padding: 9px 11px; min-height: 42px;
}
textarea { min-height: 90px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid color-mix(in srgb, var(--primary) 45%, transparent); border-color: var(--primary); }
.check { display: flex; gap: 8px; align-items: flex-start; font-weight: 500; }
.check input { margin-top: 3px; width: 18px; height: 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 11px; padding: 3px; gap: 2px; flex-wrap: wrap; }
.seg button {
  border: 0; background: transparent; font: inherit; font-size: .86rem; font-weight: 600; color: var(--muted);
  padding: 6px 11px; border-radius: 8px; cursor: pointer;
}
.seg button svg { width: 18px; height: 18px; display: block; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }

.chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: .75rem; font-weight: 700;
  padding: 2px 8px; border-radius: 999px; background: var(--surface-2); color: var(--muted); white-space: nowrap;
}
.chip.event { background: #fff0e4; color: #b4530b; }
.chip.training { background: var(--primary-soft); color: var(--primary); }
@media (prefers-color-scheme: dark) { .chip.event { background: #3b2515; color: #ffa463; } }
.chip.going { background: var(--ok-soft); color: var(--ok); }
.chip.maybe, .chip.interested { background: var(--warn-soft); color: var(--warn); }
.chip.waitlist { background: var(--danger-soft); color: var(--danger); }
.chip.cancelled { background: var(--danger-soft); color: var(--danger); }
.sport-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; flex: none; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  font-size: .72rem; font-weight: 800; color: #fff; border: 2px solid var(--surface);
}
.avatars { display: flex; }
.avatars .avatar { width: 26px; height: 26px; font-size: .62rem; margin-left: -7px; }
.avatars .avatar:first-child { margin-left: 0; }

.empty { text-align: center; color: var(--muted); padding: 34px 16px; }
.empty > svg { width: 46px; height: 46px; opacity: .45; }
.alert { padding: 10px 12px; border-radius: 10px; font-size: .9rem; margin-bottom: 12px; }
.alert.error { background: var(--danger-soft); color: var(--danger); }
.alert.info { background: var(--primary-soft); color: var(--primary); }
.alert.warn { background: var(--warn-soft); color: var(--warn); }
.alert.ok { background: var(--ok-soft); color: var(--ok); }

.toast-wrap { position: fixed; left: 0; right: 0; bottom: calc(84px + env(safe-area-inset-bottom)); display: flex; flex-direction: column; align-items: center; gap: 6px; z-index: 100; pointer-events: none; }
.toast { background: #17212e; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: .9rem; box-shadow: 0 4px 16px rgba(0,0,0,.25); max-width: 90vw; animation: pop .2s ease-out; }
.toast.error { background: var(--danger); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.spinner { width: 28px; height: 28px; border: 3px solid var(--border); border-top-color: var(--primary); border-radius: 50%; animation: spin .8s linear infinite; margin: 40px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Authentification ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px 14px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-logo { text-align: center; margin-bottom: 18px; }
.auth-logo img { width: 72px; height: 72px; border-radius: 18px; }
.auth-logo h1 { margin: 10px 0 2px; color: var(--primary); }
.code-input { font-size: 1.8rem !important; letter-spacing: .5em; text-align: center; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---------- Calendrier ---------- */
.filters { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.filters .row > select { width: auto; flex: 1; min-width: 120px; }
.filter-toggle { display: none; }
@media (max-width: 640px) {
  .filters.collapsed .more { display: none; }
  .filter-toggle { display: inline-flex; }
}
.month-head { font-weight: 800; text-transform: capitalize; color: var(--muted); font-size: .85rem; margin: 18px 4px 8px; letter-spacing: .02em; }
.act {
  display: flex; gap: 12px; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 12px; text-decoration: none; color: inherit; margin-bottom: 10px; border-left: 4px solid var(--sport, var(--primary));
}
.act:hover { background: var(--surface-2); }
.act.cancelled { opacity: .6; }
.act.cancelled .act-title { text-decoration: line-through; }
.act-date { width: 48px; text-align: center; flex: none; }
.act-date .d { font-size: 1.45rem; font-weight: 800; line-height: 1; }
.act-date .w, .act-date .m { font-size: .72rem; color: var(--muted); text-transform: uppercase; font-weight: 700; }
.act-body { flex: 1; min-width: 0; }
.act-title { font-weight: 700; font-size: 1rem; margin: 2px 0; overflow-wrap: anywhere; }
.act-meta { color: var(--muted); font-size: .84rem; }
.act-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.act-side { display: flex; flex-direction: column; justify-content: center; }
.quick-join { white-space: nowrap; }

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }
.cal-grid .dow { text-align: center; font-size: .72rem; font-weight: 700; color: var(--muted); padding: 4px 0; }
.cal-day {
  min-height: 58px; background: var(--surface); border-radius: 8px; padding: 4px; font-size: .8rem; cursor: pointer; border: 2px solid transparent;
  display: flex; flex-direction: column; gap: 2px;
}
.cal-day.other { opacity: .4; }
.cal-day.today .n { background: var(--primary); color: var(--primary-ink); border-radius: 50%; width: 22px; height: 22px; display: grid; place-items: center; }
.cal-day.sel { border-color: var(--primary); }
.cal-day .dots { display: flex; flex-wrap: wrap; gap: 2px; }
.cal-day .dots i { width: 7px; height: 7px; border-radius: 50%; display: block; }
.cal-day .dots i.ev { border-radius: 2px; }
@media (min-width: 700px) {
  .cal-day { min-height: 84px; }
  .cal-day .lbl { display: block; font-size: .7rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; border-radius: 4px; padding: 0 3px; color: #fff; }
  .cal-day .dots { display: none; }
}
@media (max-width: 699px) { .cal-day .lbl { display: none; } }

/* ---------- Détail ---------- */
.hero { border-radius: var(--radius); background: var(--surface); box-shadow: var(--shadow); overflow: hidden; }
.hero-band { height: 8px; background: var(--sport, var(--primary)); }
.hero-body { padding: 16px; }
.hero h1 { margin: 8px 0 6px; overflow-wrap: anywhere; }
.info-line { display: flex; gap: 8px; align-items: flex-start; color: var(--muted); margin: 4px 0; }
.info-line svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.part-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 14px; }
.part-actions .btn.on { background: var(--ok); border-color: var(--ok); color: #fff; }
.part-actions .btn.on-maybe { background: var(--warn); border-color: var(--warn); color: #fff; }
.tabs { display: flex; gap: 4px; overflow-x: auto; margin: 16px 0 10px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button {
  border: 0; background: var(--surface); color: var(--muted); font: inherit; font-weight: 700; font-size: .86rem;
  padding: 8px 12px; border-radius: 999px; cursor: pointer; white-space: nowrap; box-shadow: var(--shadow);
}
.tabs button.on { background: var(--primary); color: var(--primary-ink); }
.people { list-style: none; padding: 0; margin: 0; }
.people li { display: flex; align-items: center; gap: 10px; padding: 7px 0; border-bottom: 1px solid var(--border); }
.people li:last-child { border-bottom: 0; }
.group-title { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 800; margin: 14px 0 4px; }
.weather { display: flex; align-items: center; gap: 12px; }
.weather .t { font-size: 1.5rem; font-weight: 800; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 6px; }
.photos button { border: 0; padding: 0; background: var(--surface-2); border-radius: 8px; overflow: hidden; aspect-ratio: 1; cursor: pointer; position: relative; }
.photos img { width: 100%; height: 100%; object-fit: cover; display: block; }
.photos .flag { position: absolute; top: 4px; left: 4px; }
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.92); z-index: 200; display: flex; flex-direction: column; }
.lightbox .lb-img { flex: 1; display: grid; place-items: center; min-height: 0; padding: 8px; }
.lightbox img { max-width: 100%; max-height: 100%; object-fit: contain; }
.lightbox .lb-bar { display: flex; gap: 8px; padding: 10px calc(10px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)); justify-content: center; flex-wrap: wrap; color: #fff; align-items: center; }
.lightbox .btn { background: rgba(255,255,255,.12); color: #fff; border-color: transparent; }
.comment { padding: 10px 0; border-bottom: 1px solid var(--border); }
.comment:last-child { border-bottom: 0; }
.comment-head { display: flex; gap: 8px; align-items: center; font-size: .85rem; }
.comment p { margin: 6px 0 0 38px; white-space: pre-wrap; overflow-wrap: anywhere; }
.result { padding: 12px 0; border-bottom: 1px solid var(--border); }
.result:last-child { border-bottom: 0; }
.splits { display: flex; gap: 12px; flex-wrap: wrap; font-size: .85rem; color: var(--muted); margin-top: 4px; }
.splits b { color: var(--text); }
.summary { white-space: pre-wrap; margin: 8px 0 0; overflow-wrap: anywhere; }
.kudos.on { color: var(--accent); border-color: var(--accent); }
.similar-box { border: 2px dashed var(--accent); }
.geo-results { border: 1px solid var(--border); border-radius: 10px; margin-top: 6px; overflow: hidden; }
.geo-results button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--border); background: var(--surface); padding: 9px 11px; font: inherit; cursor: pointer; color: var(--text); }
.geo-results button:hover { background: var(--surface-2); }

/* ---------- Stats / tableaux ---------- */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
.tile { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow); padding: 14px; }
.tile .v { font-size: 1.7rem; font-weight: 800; }
.tile .l { color: var(--muted); font-size: .82rem; font-weight: 600; }
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); }
th { font-size: .75rem; text-transform: uppercase; color: var(--muted); letter-spacing: .03em; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.bar { height: 8px; border-radius: 4px; background: var(--primary); }

#map { height: calc(100vh - 230px); min-height: 360px; border-radius: var(--radius); box-shadow: var(--shadow); z-index: 0; }
.notif { display: flex; gap: 10px; padding: 12px; text-decoration: none; color: inherit; border-bottom: 1px solid var(--border); }
.notif.unread { background: var(--primary-soft); }
.notif svg { width: 22px; height: 22px; display: block; margin-top: 2px; }
.notif:last-child { border-bottom: 0; }
.code-box { font-family: ui-monospace, Consolas, monospace; font-size: 1.4rem; font-weight: 800; letter-spacing: .15em; background: var(--surface-2); border-radius: 10px; padding: 8px 14px; display: inline-block; }
.copy-field { display: flex; gap: 6px; }
.copy-field input { font-size: .8rem; font-family: ui-monospace, Consolas, monospace; }

/* Sections (discipline, catégorie d'âge) */
.chip.section { background: var(--surface-2); }
.section-group { margin-bottom: 8px; }
.sections-admin li { flex-wrap: wrap; gap: 6px; }
.sections-admin input[type=color], [data-secadd] input[type=color] { width: 40px; height: 34px; padding: 2px; flex: none; }
input[type=color]:disabled { opacity: .35; }

/* Préférences de notifications */
.prefs td, .prefs th { padding: 6px 4px; vertical-align: middle; }
.prefs th { font-size: .78rem; font-weight: 700; color: var(--muted); text-align: center; }
.prefs select { width: auto; min-height: 34px; padding: 4px 6px; }
.sections-admin li input[name=name], [data-secadd] input[name=name] { flex: 1 1 100% !important; }
[data-secadd] { flex-wrap: wrap; gap: 6px; }
