:root {
  --bg: #f5f7fa;
  --surface: #ffffff;
  --border: #e2e7ee;
  --border-strong: #cfd7e2;
  --text: #0f1b2d;
  --text-2: #4a5a70;
  --muted: #7b889a;
  --brand: #0063a6;
  --brand-dark: #004f86;
  --brand-soft: #e8f2fa;
  --rec: #1c7ed6;
  --rec-soft: #e7f1fc;
  --bles: #e8590c;
  --bles-soft: #fdeee5;
  --ok: #2b8a3e;
  --danger: #c92a2a;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(15, 27, 45, .05), 0 1px 3px rgba(15, 27, 45, .04);
  --shadow-lg: 0 10px 30px rgba(15, 27, 45, .12);
  --sidebar: 232px;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font: 14px/1.45 Inter, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
button, input, select { font: inherit; color: inherit; }
a { color: var(--brand); text-decoration: none; }
h1, h2, h3 { margin: 0; letter-spacing: -.01em; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Sidebar ---------- */
.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar);
  background: var(--surface); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; padding: 18px 14px; gap: 22px; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 12px; color: var(--text); padding: 0 6px; }
.brand img { width: 44px; height: 44px; }
.brand .wordmark {
  font-family: 'Barlow Condensed', Inter, sans-serif; font-style: italic; font-weight: 800;
  font-size: 34px; line-height: 1; letter-spacing: .02em; color: var(--brand);
}
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 12px; padding: 9px 12px; border-radius: 8px;
  color: var(--text-2); font-weight: 500;
}
.sidebar nav a:hover { background: var(--bg); color: var(--text); }
.sidebar nav a.active { background: var(--brand-soft); color: var(--brand); }
.sidebar nav svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.legend-side { display: flex; flex-direction: column; gap: 6px; font-size: 12px; color: var(--muted); padding: 0 8px; }
.me { margin-top: 10px; display: flex; align-items: center; gap: 10px; padding: 12px 6px 0; border-top: 1px solid var(--border); }
.me-avatar { flex: none; width: 34px; height: 34px; border-radius: 50%; background: var(--brand); color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 12.5px; }
.me-name { flex: 1; min-width: 0; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-name small { display: block; font-weight: 500; color: var(--muted); font-size: 11.5px; }
.sidebar nav { flex: 1; }
.dot { display: inline-block; width: 9px; height: 9px; border-radius: 3px; margin-right: 7px; vertical-align: -1px; }
.dot.r { background: var(--rec); }
.dot.b { background: var(--bles); }

/* ---------- Layout ---------- */
main { margin-left: var(--sidebar); padding: 28px 32px 60px; max-width: 1500px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { font-size: 22px; }
.page-head .sub { color: var(--muted); margin-top: 3px; }
.toolbar { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 14px 18px; border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.card-head h2 { font-size: 15px; }
.card-body { padding: 18px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-2.wide { grid-template-columns: 2fr 1fr; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.muted { color: var(--muted); }
.empty { padding: 40px 20px; text-align: center; color: var(--muted); }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 36px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border-strong);
  background: var(--surface); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--bg); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg); }
.btn.icon { width: 36px; padding: 0; }
.btn.sm { height: 30px; padding: 0 10px; font-size: 13px; }
.btn svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.input, select.input {
  height: 36px; padding: 0 11px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); min-width: 0;
}
.input:focus, .btn:focus-visible, .toggle:focus-visible, .cell:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; border-color: var(--brand); }
.search { position: relative; }
.search .input { padding-left: 34px; width: 240px; }
.search svg { position: absolute; left: 11px; top: 10px; width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 2; }
.seg { display: inline-flex; background: var(--bg); border: 1px solid var(--border); border-radius: 9px; padding: 3px; }
.seg button { border: 0; background: transparent; height: 29px; padding: 0 12px; border-radius: 6px; cursor: pointer; color: var(--text-2); font-weight: 500; }
.seg button.on { background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.datenav { display: flex; align-items: center; gap: 6px; }
.datenav .input { width: 150px; }

/* ---------- KPI ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 14px; margin-bottom: 18px; }
.kpi { padding: 16px 18px; }
.kpi .label { color: var(--muted); font-size: 12.5px; font-weight: 500; }
.kpi .value { font-size: 26px; font-weight: 650; margin-top: 4px; font-variant-numeric: tabular-nums; }
.kpi .hint { color: var(--muted); font-size: 12px; margin-top: 2px; }
.kpi .value .dot { width: 10px; height: 10px; }

/* ---------- Pointage ---------- */
.summary { display: flex; gap: 18px; align-items: center; color: var(--text-2); flex-wrap: wrap; }
.summary b { color: var(--text); font-variant-numeric: tabular-nums; }
.players-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 12px; }
.pcard { padding: 12px 12px 12px 14px; display: flex; flex-direction: column; gap: 10px; transition: border-color .15s, box-shadow .15s; }
.pcard.present { border-color: var(--border-strong); box-shadow: 0 0 0 1px var(--border-strong), var(--shadow); }
.pcard.has-b { border-color: var(--bles); box-shadow: 0 0 0 1px var(--bles); }
.pcard.has-r:not(.has-b) { border-color: var(--rec); box-shadow: 0 0 0 1px var(--rec); }
.pcard .who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  flex: none; width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand); font-weight: 650; font-size: 13px; font-variant-numeric: tabular-nums;
}
.who .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .meta { color: var(--muted); font-size: 12px; }
.who a { color: inherit; }
.who a:hover .name { color: var(--brand); }
.toggles { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.toggle {
  height: 38px; border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface);
  cursor: pointer; font-weight: 600; color: var(--text-2); display: flex; align-items: center; justify-content: center; gap: 6px;
  transition: background .12s, color .12s, border-color .12s;
}
.toggle .k { font-size: 11px; font-weight: 700; width: 18px; height: 18px; border-radius: 5px; display: grid; place-items: center; background: var(--bg); color: var(--muted); }
.toggle.r:hover { border-color: var(--rec); color: var(--rec); }
.toggle.b:hover { border-color: var(--bles); color: var(--bles); }
.toggle.r.on { background: var(--rec); border-color: var(--rec); color: #fff; }
.toggle.b.on { background: var(--bles); border-color: var(--bles); color: #fff; }
.toggle.on .k { background: rgba(255, 255, 255, .22); color: #fff; }
.toggle[disabled] { opacity: .6; cursor: wait; }
.note-input { height: 32px; font-size: 13px; border-color: var(--border); background: var(--bles-soft); border-color: transparent; }
.note-input::placeholder { color: #b86a3f; }

/* ---------- Planning (grille mensuelle) ---------- */
.table-wrap { overflow: auto; max-width: 100%; }
table { border-collapse: separate; border-spacing: 0; width: 100%; }
.month-table { font-size: 12.5px; width: auto; min-width: 100%; }
.month-table th, .month-table td { border-bottom: 1px solid var(--border); border-right: 1px solid var(--border); padding: 0; text-align: center; }
.month-table thead th { position: sticky; top: 0; background: var(--surface); z-index: 2; font-weight: 600; color: var(--text-2); }
.month-table .day-h { padding: 6px 0 2px; min-width: 50px; }
.month-table .day-h small { display: block; color: var(--muted); font-weight: 500; font-size: 10.5px; }
.month-table .sub-h th { font-size: 10.5px; color: var(--muted); padding: 2px 0 4px; top: 41px; }
.month-table .name-c { position: sticky; left: 0; background: var(--surface); z-index: 1; text-align: left; padding: 0 12px; min-width: 170px; white-space: nowrap; font-weight: 600; }
.month-table thead .name-c { z-index: 3; }
.month-table .name-c a { color: var(--text); }
.month-table .name-c a:hover { color: var(--brand); }
.month-table .we { background: #f8f9fb; }
.month-table .today-c { background: var(--brand-soft) !important; }
.cell { width: 25px; height: 30px; border: 0; background: transparent; cursor: pointer; font-weight: 700; font-size: 11px; color: transparent; display: block; }
.cell:hover { background: var(--bg); color: var(--muted); }
.cell.r.on { background: var(--rec); color: #fff; }
.cell.b.on { background: var(--bles); color: #fff; }
.month-table td.split { border-right: 1px dashed var(--border); }
.month-table .tot { font-weight: 650; min-width: 40px; padding: 0 8px; font-variant-numeric: tabular-nums; }
.month-table tfoot td { font-weight: 650; color: var(--text-2); padding: 6px 0; background: #fafbfc; font-variant-numeric: tabular-nums; }

/* ---------- Tableaux de données ---------- */
.data-table th, .data-table td { padding: 10px 14px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
.data-table th { font-size: 12px; font-weight: 600; color: var(--muted); background: #fafbfc; position: sticky; top: 0; }
.data-table th.sortable { cursor: pointer; user-select: none; }
.data-table th.sortable:hover { color: var(--text); }
.data-table th .arrow { font-size: 10px; margin-left: 3px; }
.data-table td.r, .data-table th.r { text-align: right; font-variant-numeric: tabular-nums; }
.data-table tbody tr:hover { background: #fafbfd; }
.data-table tbody tr.clickable { cursor: pointer; }
.data-table tr:last-child td { border-bottom: 0; }
.data-table .inactive td { color: var(--muted); }
.pill { display: inline-flex; align-items: center; height: 22px; padding: 0 8px; border-radius: 11px; font-size: 12px; font-weight: 600; }
.pill.r { background: var(--rec-soft); color: #145ea3; }
.pill.b { background: var(--bles-soft); color: #b3450a; }
.pill.gray { background: var(--bg); color: var(--muted); }
.minibar { display: flex; gap: 2px; height: 8px; width: 140px; }
.minibar i { display: block; height: 100%; border-radius: 2px; }
.minibar .r { background: var(--rec); }
.minibar .b { background: var(--bles); }

/* ---------- Charts ---------- */
.chart { position: relative; width: 100%; }
.chart svg { display: block; width: 100%; overflow: visible; }
.chart .grid line { stroke: var(--border); stroke-width: 1; }
.chart .axis text { fill: var(--muted); font-size: 11px; font-variant-numeric: tabular-nums; }
.chart .hit { fill: transparent; cursor: default; }
.chart .col:hover .hit { fill: rgba(15, 27, 45, .04); }
.chart-legend { display: flex; gap: 16px; font-size: 12.5px; color: var(--text-2); }
#tooltip {
  position: fixed; pointer-events: none; z-index: 100; background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-lg); border-radius: 8px; padding: 8px 11px; font-size: 12.5px; min-width: 130px; opacity: 0; transition: opacity .1s;
}
#tooltip.show { opacity: 1; }
#tooltip .t { font-weight: 600; margin-bottom: 4px; }
#tooltip .row { display: flex; justify-content: space-between; gap: 14px; color: var(--text-2); }
#tooltip .row b { color: var(--text); font-variant-numeric: tabular-nums; }
.split-bar { display: flex; height: 12px; gap: 2px; border-radius: 4px; overflow: hidden; margin: 10px 0 8px; }
.split-bar i { display: block; height: 100%; }

/* ---------- Joueurs ---------- */
.form-row { display: grid; grid-template-columns: 2fr 2fr 90px 1.5fr auto; gap: 10px; align-items: end; }
.form-row.kine-form { grid-template-columns: minmax(0, 420px) auto; justify-content: start; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-2); margin-bottom: 5px; }
.field .input { width: 100%; }
.req { color: var(--danger); }

/* ---------- Fiche joueur ---------- */
.back { display: inline-flex; align-items: center; gap: 6px; color: var(--text-2); margin-bottom: 12px; font-weight: 500; }
.back svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2; }
.back:hover { color: var(--brand); }
.player-hero { display: flex; align-items: center; gap: 14px; }
.player-hero .avatar { width: 52px; height: 52px; font-size: 18px; }
.player-hero h1 { font-size: 22px; }
.history { max-height: 520px; overflow: auto; }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); background: var(--text); color: #fff;
  padding: 10px 16px; border-radius: 8px; font-weight: 500; opacity: 0; pointer-events: none; transition: .2s; z-index: 200;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); }

.error-box { border: 1px solid #f1c0c0; background: #fff5f5; color: #8a1f1f; border-radius: var(--radius); padding: 16px 18px; }
.error-box code { background: #fde2e2; padding: 1px 5px; border-radius: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .grid-2, .grid-2.wide { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr 1fr; }
  .form-row .actions { grid-column: 1 / -1; }
}
@media (max-width: 860px) {
  :root { --sidebar: 0px; }
  .sidebar { inset: auto 0 0 0; width: auto; height: 62px; flex-direction: row; padding: 0 8px; border-right: 0; border-top: 1px solid var(--border); }
  .sidebar .brand, .legend-side, .me-name, .me-avatar { display: none; }
  .me { margin: 0; padding: 0; border: 0; }
  .sidebar nav { flex-direction: row; flex: 1; justify-content: space-around; align-items: center; }
  .sidebar nav a { flex-direction: column; gap: 2px; font-size: 10.5px; padding: 6px 4px; }
  .form-row.kine-form { grid-template-columns: 1fr; }
  main { padding: 18px 16px 90px; }
  .search .input { width: 100%; }
  .search { flex: 1; }
  .players-grid { grid-template-columns: 1fr; }
}

/* ---------- Connexion ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--surface); }
.login { width: 100%; max-width: 320px; display: flex; flex-direction: column; align-items: stretch; gap: 12px; text-align: center; }
.login-logo { width: 190px; height: 190px; margin: 0 auto 22px; }
.login-select { height: 46px; font-size: 15px; padding: 0 14px; cursor: pointer; }
.login-btn { height: 46px; font-size: 15px; }
.login-error { color: var(--danger); font-size: 13px; }

/* Infobulle « qui a fait quoi » */
[data-tip] { cursor: default; }
.toggle[data-tip], .cell[data-tip] { cursor: pointer; }
#tooltip .by { color: var(--text-2); }
#tooltip .by b { color: var(--text); }
.log-day { padding: 10px 18px; font-weight: 600; font-size: 12.5px; color: var(--muted); background: #fafbfc; border-bottom: 1px solid var(--border); position: sticky; top: 0; }
.log-row { display: flex; gap: 14px; align-items: center; padding: 10px 18px; border-bottom: 1px solid var(--border); }
.log-row .time { width: 44px; color: var(--muted); font-variant-numeric: tabular-nums; flex: none; }
.log-row .who { width: 120px; flex: none; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.log-row .what { flex: 1; min-width: 0; }
.log-row .what a { color: var(--text); font-weight: 600; }
.log-row .what a:hover { color: var(--brand); }
@media (max-width: 600px) { .log-row { flex-wrap: wrap; gap: 4px 12px; } .log-row .what { flex-basis: 100%; } }
