:root {
  --bg: #f4f6fa; --surface: #fff; --surface-2: #f0f3f8; --surface-3: #f6f8fc;
  --border: #e8ecf3; --border-2: #dfe5ef; --border-3: #eef1f6;
  --text: #1e2430; --text-soft: #42506b; --text-muted: #67718a; --text-faint: #8a94ab;
  --primary: #203764; --primary-hover: #2c4a85;
  --btn: #dfe6f1; --btn-ok-bg: #e1f5e9; --btn-ok: #1c7a43;
  --btn-danger-bg: #fde8e8; --btn-danger: #b02a2a;
  --input-border: #ccd4e0; --select-bg: #e7eeff; --slot-hover: #e3f2fd;
  --row-home: #eef7ff; --row-ext: #fff8f0; --row-hover: #e8f0fb; --row-past: #f0f0f0;
  --row-conflict-bg: #ffe9e9; --row-conflict: #b00020;
  --focus: #5b8def; --text-accent: #203764;
  --nav-active-bg: #fff; --nav-active-fg: #203764;
}
/* Thème sombre : palette complète redéfinie — toutes les surfaces, bordures,
   textes et boutons suivent les mêmes variables (aucun rustin par sélecteur). */
body[data-theme="dark"] {
  --bg: #10141d; --surface: #1b2230; --surface-2: #232c3c; --surface-3: #151b27;
  --border: #313d54; --border-2: #2d3850; --border-3: #28324a;
  --text: #dde4f0; --text-soft: #b9c5da; --text-muted: #9aaccc; --text-faint: #7e8ca6;
  --primary: #33518f; --primary-hover: #3d5fa8;
  --btn: #2e3a52; --btn-ok-bg: #1d3a29; --btn-ok: #8fe0a8;
  --btn-danger-bg: #4a2020; --btn-danger: #ffabab;
  --input-border: #3c4a66; --select-bg: #2b3a55; --slot-hover: #24405e;
  --row-home: #1e2c44; --row-ext: #3a2e1e; --row-hover: #26344c; --row-past: #161c28;
  --row-conflict-bg: #45201f; --row-conflict: #ff9d9d;
  --focus: #6b93e8; --text-accent: #9db8e8;
  --nav-active-bg: #e8eefb; --nav-active-fg: #152341;
}
* { box-sizing: border-box; }
img { object-fit: contain; }
body { font-family: 'Segoe UI', system-ui, sans-serif; margin: 0; background: var(--bg); color: var(--text); }
header { background: var(--primary); color: #fff; padding: 12px 24px; display: flex; align-items: center; gap: 32px; flex-wrap: wrap; }
header h1 { font-size: 20px; margin: 0; }
nav { display: flex; gap: 6px; flex-wrap: wrap; }
nav button { background: rgba(255,255,255,.12); color: #fff; border: none; padding: 8px 14px; border-radius: 6px; cursor: pointer; font-size: 14px; }
nav button.active { background: var(--nav-active-bg); color: var(--nav-active-fg); font-weight: 700; }
main { padding: 24px; max-width: 1300px; margin: auto; }
.card { background: var(--surface); border-radius: 10px; padding: 20px; margin-bottom: 20px; box-shadow: 0 1px 4px rgba(0,0,0,.08); }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(380px, 1fr)); gap: 20px; align-items: start; }
h2 { font-size: 17px; margin-top: 0; border-bottom: 2px solid var(--border); padding-bottom: 8px; }
h3 { font-size: 15px; }
.row { display: flex; gap: 8px; align-items: center; margin: 10px 0; flex-wrap: wrap; }
.grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 12px; }
input, select, textarea { padding: 7px 10px; border: 1px solid var(--input-border); border-radius: 6px; font-size: 14px; flex: 1; min-width: 120px; }
textarea { width: 100%; font-family: 'Consolas', monospace; resize: vertical; margin-top: 6px; }
button { padding: 7px 14px; border: none; border-radius: 6px; background: var(--btn); cursor: pointer; font-size: 14px; }
button.primary { background: var(--primary); color: #fff; padding: 10px 18px; }
button.danger { background: var(--btn-danger-bg); color: var(--btn-danger); }
button.ok { background: var(--btn-ok-bg); color: var(--btn-ok); }
table { width: 100%; border-collapse: collapse; margin-top: 10px; font-size: 14px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { background: var(--surface-2); font-size: 13px; }
tr.home td { background: var(--row-home); }
tr.conflict td { background: var(--row-conflict-bg); color: var(--row-conflict); font-weight: 600; }
tr.conflict td input, tr.conflict td select { color: var(--row-conflict); font-weight: 600; }
ul { list-style: none; padding: 0; }
ul li { display: flex; justify-content: space-between; align-items: center; padding: 7px 4px; border-bottom: 1px solid var(--border-3); cursor: pointer; }
ul li.selected { background: var(--select-bg); border-radius: 6px; }
.hint { color: var(--text-muted); font-size: 13px; }
/* Liens (noms d'équipe cliquables) : jamais la couleur par défaut du navigateur,
   sombre sur fond sombre — couleur d'accent adaptée aux deux thèmes. */
a { color: var(--text-accent); }
a:hover { color: var(--focus); }
/* Indication « N° féd. » sur les cartes/blocs : couleur d'accent lisible */
.fed-id { color: var(--text-accent); font-size: 11px; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 10px; font-size: 12px; font-weight: 600; }
.badge.dom { background: #d9ecff; color: #14549c; }
.badge.ext { background: #ffe9d9; color: #a05a00; }
.badge.conf { background: #ffe3c2; color: #96540a; }
#toast { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; }
.toast-msg { background: var(--primary); color: #fff; padding: 10px 16px; border-radius: 8px; font-size: 14px; box-shadow: 0 2px 8px rgba(0,0,0,.2); max-width: 480px; }
.toast-msg.error { background: #b02a2a; }
tr.past td { background: var(--row-past); color: var(--text-faint); }
tr.past .badge { background: #cfd8dc; color: #37474f; }

/* ---------- Agenda WE ---------- */
/* Barre d'outils (gymnases cochables + WE) */
.ag-toolbar { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; margin: 12px 0 16px;
  padding: 10px 12px; background: var(--surface-3); border: 1px solid var(--border); border-radius: 10px; }
#ag-gyms { display: flex; gap: 8px; flex-wrap: wrap; }
.ag-gymchip { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; font-size: 13px;
  background: var(--surface); border: 1.5px solid var(--gc, #1e88e5); border-radius: 20px; cursor: pointer;
  color: var(--text-soft); user-select: none; transition: all .15s; }
.ag-gymchip::before { content: ''; width: 9px; height: 9px; border-radius: 50%; background: var(--gc); }
.ag-gymchip input { display: none; }
.ag-gymchip:has(input:checked) { background: var(--gc); border-color: var(--gc); color: #fff; font-weight: 600; }
.ag-gymchip:has(input:not(:checked)) { opacity: .55; border-style: dashed; }
.ag-gymchip:has(input:not(:checked))::before { background: transparent; box-shadow: inset 0 0 0 1.5px var(--gc); }

/* Wrapper : agenda + panneau latéral */
.ag-wrap { display: flex; gap: 18px; align-items: flex-start; }
#agenda { flex: 1; min-width: 0; }
.ag-side { width: 280px; flex-shrink: 0; background: var(--surface-3); border: 1px solid var(--border);
  border-radius: 10px; padding: 12px; position: sticky; top: 12px; max-height: calc(100vh - 30px); overflow-y: auto; }
.ag-side h3 { margin: 0 0 4px; font-size: 14px; border: none; }
.ag-side h3 small { color: var(--text-faint); font-weight: 400; }

/* Sections jour : une grille par jour, une colonne par gymnase */
.ag-sec { margin-bottom: 14px; }
.ag-sechead { display: flex; align-items: baseline; gap: 10px; margin-bottom: 6px;
  padding: 8px 12px; background: var(--primary); color: #fff; border-radius: 8px; cursor: pointer; user-select: none; }
.ag-sechead:hover { background: var(--primary-hover); }
.ag-sec.closed .ag-sechead { opacity: .65; background: #48608f; }
.ag-chev { font-size: 12px; width: 14px; }
.ag-sec.closed .ag-secbody { display: none; }
.ag-sec.closed .ag-seccount { background: rgba(255,255,255,.1); font-style: italic; }
.ag-secday { font-weight: 700; font-size: 15px; text-transform: capitalize; }
.ag-secdate { opacity: .85; font-size: 13px; }
.ag-seccount { margin-left: auto; font-size: 12px; background: rgba(255,255,255,.18); padding: 2px 10px; border-radius: 10px; }
.ag-grid { display: grid; gap: 0; border: 1px solid var(--border-2); border-radius: 0 0 8px 8px; overflow: hidden; }
.ag-time { border-right: 1px solid var(--border-2); background: var(--surface-3); text-align: right; }
.ag-time > div { font-size: 11px; color: var(--text-faint); padding-right: 8px; line-height: 1; }
.ag-colhead { height: 30px; line-height: 30px; text-align: center; font-size: 12.5px; font-weight: 600;
  color: var(--gc, #1e88e5); background: var(--surface); border-bottom: 2px solid var(--gc, #1e88e5);
  border-left: 1px solid var(--border-2); padding: 0 6px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ag-col { position: relative; border-left: 1px solid var(--border-3); }
.ag-slot { border-bottom: 1px dashed var(--border); }
.ag-slot:nth-child(even) { border-bottom: 1px solid var(--border-3); }
.ag-slot.hover { background: var(--slot-hover); outline: 1px solid #90caf9; outline-offset: -1px; }
.ag-block { position: absolute; left: 4px; right: 4px; color: #fff; border-radius: 6px;
  padding: 3px 7px; font-size: 11px; line-height: 1.25; overflow: hidden; cursor: grab;
  box-shadow: 0 2px 5px rgba(20,30,60,.25); display: flex; flex-direction: column; align-items: flex-start; }
.ag-block .bl-line1 { display: flex; align-items: center; gap: 4px; min-width: 0; }
.ag-block .bl-line1 b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ag-block .bl-time { margin-left: auto; opacity: .9; white-space: nowrap; font-variant-numeric: tabular-nums; }
.ag-block .bl-vs { display: flex; align-items: center; gap: 4px; min-width: 0; opacity: .95; }
.ag-block .bl-vs img { height: 14px; flex-shrink: 0; }
.ag-block .bl-opp { overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  font-size: 11.5px; line-height: 1.2; word-break: break-word; }
.ag-block img { object-fit: contain; }
.ag-block .bl-line1 img { height: 14px; width: auto; max-width: 100%; flex-shrink: 0; }
.ag-block .ag-fed { align-self: flex-start; margin-top: 2px; font-size: 10px; font-weight: 700;
  padding: 0 6px; border-radius: 8px; background: rgba(255,255,255,.22); white-space: nowrap; }
.ag-block .ag-fed.ok { background: #a5d6a7; color: #1b5e20; }
.ag-block .ag-fed.diff { background: #ffcc80; color: #8d3e00; }
.ag-block .ag-fed.none { background: rgba(255,255,255,.25); color: rgba(255,255,255,.9); font-weight: 500; }
.ag-block.conflict { outline: 2px solid #c62828; }
.ag-block.past { opacity: .45; cursor: default; }

/* Cartes « à planifier » */
.ag-poolcard { display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--border-2);
  border-left: 4px solid var(--tc, #3949ab); border-radius: 8px; padding: 8px 10px; margin: 7px 0;
  cursor: grab; box-shadow: 0 1px 3px rgba(20,30,60,.07); transition: box-shadow .15s, transform .15s; }
.ag-poolcard:hover { box-shadow: 0 3px 8px rgba(20,30,60,.16); transform: translateY(-1px); }
.ag-poolj { background: var(--select-bg); color: var(--text-accent); font-weight: 700; font-size: 12px;
  border-radius: 6px; padding: 4px 7px; flex-shrink: 0; }
.ag-poolteam { font-size: 13px; }
.ag-poolteam img { height: 16px; width: auto; vertical-align: -3px; }
.ag-poolopp { font-size: 12px; color: var(--text-muted); }
.ag-poolfed { font-size: 11px; color: var(--text-faint); }
.ag-pooldate { font-size: 11px; color: var(--text-soft); background: var(--surface-2); border-radius: 4px; padding: 2px 6px; margin-top: 2px; display: inline-block; }

/* ---------- Vue Planning du WE (tableau) ---------- */
.weq-tblwrap { border: 1px solid var(--border-2); border-radius: 10px; overflow: auto; background: var(--surface); }
.weq-table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.weq-table td { padding: 8px 12px; border-bottom: 1px solid var(--border-3); vertical-align: middle; }
.weq-dayhead td { background: var(--primary); color: #fff; font-weight: 700; font-size: 13px;
  padding: 8px 12px; border-bottom: none; }
.weq-dayhead td > span { font-weight: 400; opacity: .85; margin-left: 8px; }
.weq-dayhead .weq-daycount { float: right; background: rgba(255,255,255,.18);
  padding: 1px 10px; border-radius: 10px; font-size: 12px; font-weight: 600; opacity: 1; }
.weq-mrow.dom { background: var(--row-home); }
.weq-mrow.ext { background: var(--surface)8f0; }
.weq-mrow:hover { background: var(--row-hover); }
.weq-time { font-variant-numeric: tabular-nums; font-weight: 700; color: var(--text-accent); white-space: nowrap; width: 60px; }
.weq-team img, .weq-opp img { height: 20px; vertical-align: -5px; }
.weq-lieu { color: var(--text-muted); }
.weq-mrow .badge { margin-right: 6px; }

/* ---------- Paramétrage : cartes pleine largeur (gymnases, planning type) ---------- */
#tab-parametrage .cols > .card:nth-child(n+4) { grid-column: 1 / -1; }
#gym-table input { min-width: 0; }
#gym-table td:nth-child(1) input { width: 100%; }
#gym-table td:nth-child(2) input { width: 100%; }
#gym-table td:nth-child(3) input { width: 90px; }
#gym-table td:last-child { white-space: nowrap; width: 84px; }

/* ---------- Badge catégorie d'équipe ---------- */
.cat-badge { display: inline-block; background: #37474f; color: #fff; font-size: 10.5px;
  font-weight: 700; padding: 1px 7px; border-radius: 9px; vertical-align: 1px; letter-spacing: .4px; }

/* Fenêtre de saisie manuelle d'un horaire (clic sur une carte/bloc de l'agenda) */
#plan-modal { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: center; justify-content: center; z-index: 50; }
#plan-modal[hidden] { display: none; }
.pm-box { background: var(--surface); border-radius: 12px; padding: 18px 20px; width: min(400px, 92vw); box-shadow: 0 8px 30px rgba(0,0,0,.25); }
.pm-box h3 { margin: 0 0 4px; }
.pm-box label { display: block; margin: 10px 0 0; font-size: 13px; color: var(--text-soft); }
.pm-box select, .pm-box input { width: 100%; margin-top: 4px; padding: 7px 8px; border: 1px solid var(--input-border); border-radius: 6px; font-size: 14px; }
.pm-actions { display: flex; gap: 8px; margin-top: 16px; align-items: center; }
.ag-poolcard, .ag-block { cursor: pointer; }
.pn-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: end; margin-top: 8px; }
.pn-row label { display: flex; flex-direction: column; font-size: 12px; color: var(--text-muted); gap: 3px; }
.pn-row input, .pn-row select { padding: 6px 8px; border: 1px solid var(--input-border); border-radius: 6px; font-size: 14px; }
.pn-row button { margin-bottom: 2px; }

/* ---------- Zone utilisateur (en-tête) ---------- */
#userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; }
#theme-btn { background: rgba(255,255,255,.12); color: #fff; border: none; border-radius: 6px;
  padding: 7px 10px; cursor: pointer; font-size: 15px; line-height: 1; }
.user-chip { font-size: 13.5px; opacity: .95; white-space: nowrap; }
#userbox button { font-size: 13px; padding: 7px 12px; border-radius: 6px; border: none; cursor: pointer;
  background: rgba(255,255,255,.12); color: #fff; }
#userbox button:hover { background: rgba(255,255,255,.25); }
#login-overlay { position: fixed; inset: 0; background: rgba(15, 23, 42, .5); display: flex;
  align-items: center; justify-content: center; z-index: 60; }
#login-overlay[hidden] { display: none; }

/* ---------- Formulaire Utilisateurs : grille propre (3 colonnes -> 1 en mobile) ---------- */
.user-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px 18px; margin: 16px 0; }
.user-grid .fg-cell { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.user-grid .fg-cell > label { font-size: 12.5px; font-weight: 700; color: var(--text-muted); }
.user-grid input, .user-grid select, .user-grid .msel { width: 100%; min-width: 0; }
@media (max-width: 760px) { .user-grid { grid-template-columns: 1fr; } }

/* ---------- Formulaires alignés (Nouvelle équipe) ---------- */
.form-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 12px 16px; margin: 14px 0; align-items: stretch; }
.form-grid label, .form-grid .fg-label { display: flex; flex-direction: column; gap: 5px;
  font-size: 13px; font-weight: 600; color: var(--text-muted); }
.form-grid input, .form-grid select, .form-grid .msel { width: 100%; min-width: 0; }

/* ---------- Multiselect catégories ---------- */
.msel { position: relative; }
.msel-btn { width: 100%; display: flex; align-items: center; gap: 6px; text-align: left;
  padding: 7px 10px; border: 1px solid var(--input-border); border-radius: 6px;
  background: var(--surface); font-size: 14px; color: var(--text); cursor: pointer; }
.msel-btn .msel-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msel-btn.is-set .msel-label { font-weight: 600; color: var(--text-accent); }
.msel-panel { position: absolute; z-index: 40; top: calc(100% + 4px); left: 0; min-width: 100%;
  background: var(--surface); border: 1px solid var(--input-border); border-radius: 8px; padding: 6px;
  box-shadow: 0 6px 20px rgba(15,23,42,.18); max-height: 220px; overflow: auto; }
.msel-panel[hidden] { display: none; }
.msel-opt { display: flex; align-items: center; gap: 8px; padding: 6px 8px; border-radius: 6px;
  font-size: 14px; cursor: pointer; font-weight: 400; color: var(--text); }
.msel-opt:hover { background: var(--select-bg); }
.msel-opt input { min-width: auto; width: auto; }
body[data-theme="dark"] .msel-btn { background: #262f3f; }

/* Focus visible sur tous les champs (clair et sombre) */
input:focus, select:focus, textarea:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: var(--focus); }

/* Spécificités du thème sombre non couvertes par les variables */
body[data-theme="dark"] header { background: #101a30; border-bottom: 1px solid #26324e; }
body[data-theme="dark"] nav button { background: rgba(255,255,255,.08); color: #dde4f0; font-weight: 500; }
body[data-theme="dark"] nav button:hover { background: rgba(255,255,255,.18); }
body[data-theme="dark"] nav button.active { background: var(--nav-active-bg); color: var(--nav-active-fg); }
body[data-theme="dark"] #userbox button, body[data-theme="dark"] #theme-btn { background: rgba(255,255,255,.08); color: #dde4f0; }
body[data-theme="dark"] #userbox button:hover { background: rgba(255,255,255,.18); }
body[data-theme="dark"] .user-chip { color: #c3cee4; }
body[data-theme="dark"] input, body[data-theme="dark"] select, body[data-theme="dark"] textarea {
  background: #262f3f; color: var(--text); }
body[data-theme="dark"] input::placeholder, body[data-theme="dark"] textarea::placeholder { color: #7e8ca6; }
body[data-theme="dark"] .ag-sechead, body[data-theme="dark"] .weq-dayhead td { background: #101a30; }
body[data-theme="dark"] .ag-sec.closed .ag-sechead { background: #2c3a58; }
body[data-theme="dark"] .msel-panel { box-shadow: 0 8px 28px rgba(0,0,0,.55); }
body[data-theme="dark"] .pm-box { box-shadow: 0 8px 30px rgba(0,0,0,.55); }
body[data-theme="dark"] .ag-poolj { background: var(--select-bg); color: #cfd9ee; }
body[data-theme="dark"] .badge.dom { background: #1d3550; color: #a3c8f0; }
body[data-theme="dark"] .badge.ext { background: #46341d; color: #f0b877; }
body[data-theme="dark"] .badge.conf { background: #46341d; color: #f0c98a; }
body[data-theme="dark"] .cat-badge { background: #3d4c66; color: #dde4f0; }
/* Options des selects natifs en thème sombre (le fond des <option> est géré
   par l'OS, on force le texte pour rester lisible) */
body[data-theme="dark"] select option { background: #262f3f; color: var(--text); }
