:root {
  --bg: #f4efe8;
  --canvas: #f4efe8;
  --surface: #ffffff;
  --surface-2: #fbf8f4;
  --sidebar-1: #2b2019;
  --sidebar-2: #3a2a20;
  --sidebar-text: #cdbfb2;
  --sidebar-muted: #8a7868;
  --border: #eadfd2;
  --border-strong: #ddceba;
  --text: #241d17;
  --muted: #907f70;
  --brand: #8b5e3c;
  --brand-600: #774f31;
  --accent: #c67b4a;
  --danger: #bb3b2c;
  --danger-bg: #fbeae7;
  --ok: #2f8f4e;
  --ok-bg: #e6f4ea;
  --admin-bg: #efe2f8;
  --admin-fg: #7b3fa8;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow-sm: 0 1px 2px rgba(43, 32, 25, .05);
  --shadow-md: 0 6px 22px rgba(43, 32, 25, .09);
  --shadow-lg: 0 18px 50px rgba(43, 32, 25, .16);
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: var(--font);
  background: var(--canvas);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv02", "cv03", "cv04";
}
a { color: var(--brand); }
h1 { font-size: 26px; font-weight: 700; letter-spacing: -.02em; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 600; letter-spacing: -.01em; margin: 0 0 14px; }
.muted { color: var(--muted); }

/* ---------- Layout ---------- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: 256px; flex-shrink: 0;
  background: linear-gradient(180deg, var(--sidebar-1), var(--sidebar-2));
  color: var(--sidebar-text);
  display: flex; flex-direction: column;
  padding: 22px 16px;
  position: sticky; top: 0; height: 100vh;
}
.sb-brand {
  display: flex; align-items: center; gap: 10px;
  font-size: 17px; font-weight: 600; color: #fff;
  padding: 6px 10px 22px;
}
.sb-brand b { font-weight: 700; }
.sb-logo {
  width: 34px; height: 34px; display: grid; place-items: center;
  background: rgba(199, 123, 74, .22); border-radius: 10px; font-size: 18px;
}
.sb-logo-img {
  width: 34px; height: 34px; border-radius: 9px; object-fit: cover;
  display: block; box-shadow: 0 1px 3px rgba(0, 0, 0, .25);
}
.sb-nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.sb-nav a {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px; border-radius: 10px;
  color: var(--sidebar-text); text-decoration: none;
  font-size: 14px; font-weight: 500;
  transition: background .15s, color .15s;
}
.sb-nav a svg { width: 18px; height: 18px; opacity: .8; }
.sb-nav a:hover { background: rgba(255, 255, 255, .06); color: #fff; }
.sb-nav a.active { background: rgba(199, 123, 74, .20); color: #fff; }
.sb-nav a.active svg { opacity: 1; color: var(--accent); }

.sb-footer { border-top: 1px solid rgba(255, 255, 255, .08); padding-top: 14px; }
.sb-user { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; padding: 0 4px; }
.sb-avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: var(--accent); color: #fff; display: grid; place-items: center;
  font-weight: 600; font-size: 15px; flex-shrink: 0;
}
.sb-user-meta { display: flex; flex-direction: column; min-width: 0; }
.sb-email { font-size: 13px; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-role { font-size: 11px; color: var(--sidebar-muted); }
.sb-logout {
  width: 100%; background: rgba(255, 255, 255, .06); color: var(--sidebar-text);
  border: 1px solid rgba(255, 255, 255, .08); padding: 9px; border-radius: 9px;
  cursor: pointer; font-size: 13px; font-family: var(--font); transition: background .15s;
}
.sb-logout:hover { background: rgba(255, 255, 255, .12); color: #fff; }

.main { flex: 1; min-width: 0; }
.main-inner { max-width: 1040px; margin: 0 auto; padding: 40px 40px 64px; }
.page-head { margin-bottom: 28px; }

/* ---------- Cards / stats ---------- */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin: 4px 0 28px; }
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden; transition: box-shadow .2s, transform .2s;
}
.stat:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.stat::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 3px; background: var(--accent); opacity: .0; transition: opacity .2s; }
.stat:hover::before { opacity: 1; }
.stat-num { font-size: 32px; font-weight: 700; letter-spacing: -.02em; line-height: 1; }
.stat-label { color: var(--muted); font-size: 13px; margin-top: 6px; }

/* ---------- Panels ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 22px 24px; margin: 18px 0; box-shadow: var(--shadow-sm);
}
.panel h2 { margin-top: 0; }
.module-list { display: grid; gap: 10px; }
.module-list a {
  display: flex; align-items: center; gap: 14px; text-decoration: none; color: inherit;
  padding: 14px 16px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface-2); transition: border-color .15s, transform .15s;
}
.module-list a:hover { border-color: var(--border-strong); transform: translateX(2px); }
.module-list .m-title { font-weight: 600; font-size: 14px; }
.module-list .m-desc { color: var(--muted); font-size: 13px; }
.module-list .m-arrow { margin-left: auto; color: var(--muted); display: flex; }
.module-list .m-arrow .icon { width: 18px; height: 18px; }

/* Icones Lucide */
.icon { width: 18px; height: 18px; flex-shrink: 0; }

/* Formulaires */
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; }
form label { display: block; font-size: 13px; color: var(--muted); font-weight: 500; }
form label.block { margin-bottom: 4px; }
form input, form select {
  width: 100%; margin-top: 6px; padding: 10px 12px; font-size: 15px; font-family: var(--font);
  border: 1px solid var(--border-strong); border-radius: 10px; background: var(--surface); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
form input:focus, form select:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139, 94, 60, .12); }
form .actions { margin-top: 4px; }
.flash-ok { background: var(--ok-bg); color: var(--ok); border: 1px solid #bfe4c8; padding: 11px 14px; border-radius: 10px; margin-bottom: 18px; font-size: 14px; }
.inline-upload { display: flex; align-items: center; gap: 8px; margin: 0; }
.inline-upload input[type=file] { width: auto; margin: 0; font-size: 12px; padding: 6px; }
.inline-upload .btn { padding: 7px 12px; font-size: 13px; }
form input[type=file] { padding: 8px; background: var(--surface-2); }

/* Editeur de niveaux (compétitions) */
.niveau-row { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 12px; border: 1px solid var(--border); border-radius: 10px; margin-bottom: 10px; background: var(--surface-2); }
.niveau-row input, .niveau-row select { width: auto; margin: 0; padding: 8px 10px; font-size: 14px; }
.niveau-row .nv-nom { flex: 1; min-width: 150px; }
.niveau-row .nv-reprise, .niveau-row .nv-terrain { width: 90px; }
.niveau-row .nv-repriseNiveau, .niveau-row .nv-jour { width: 130px; }
.niveau-row .nv-catlbl { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; color: var(--text); font-weight: 400; }
.niveau-row .nv-catlbl input { width: auto; }
.niveau-row .nv-remove { padding: 7px 10px; font-size: 12px; margin-left: auto; }
.check-line { display: flex; align-items: flex-start; gap: 10px; font-weight: 400; color: var(--text); font-size: 14px; }
.check-line input { width: auto; margin-top: 3px; }

/* ---------- Tables ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); overflow: hidden; }
.table-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 14px 18px; font-size: 14px; }
thead th {
  color: var(--muted); font-weight: 600; font-size: 11px; text-transform: uppercase;
  letter-spacing: .05em; background: var(--surface-2); border-bottom: 1px solid var(--border);
}
tbody td { border-bottom: 1px solid var(--border); }
tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background .12s; }
tbody tr:hover { background: var(--surface-2); }
.row-disabled { opacity: .5; }
.cell-link { color: var(--brand); text-decoration: none; font-weight: 500; }
.cell-link:hover { text-decoration: underline; }
.cell-strong { font-weight: 500; }

/* ---------- Badges / tags ---------- */
.tag { background: #efe6db; color: var(--brand-600); padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.badge { padding: 3px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; display: inline-block; }
.badge-admin { background: var(--admin-bg); color: var(--admin-fg); }
.badge-on { background: var(--ok-bg); color: var(--ok); }
.badge-off { background: var(--danger-bg); color: var(--danger); }
.badge-neutral { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }

/* ---------- Buttons ---------- */
.btn { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font); font-size: 14px; font-weight: 500; padding: 10px 18px; border-radius: var(--radius-sm); cursor: pointer; border: 1px solid transparent; transition: background .15s, box-shadow .15s, border-color .15s; text-decoration: none; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover { background: var(--brand-600); }
.btn-ghost { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--surface); color: var(--danger); border-color: #eabfb8; }
.btn-danger:hover { background: var(--danger-bg); }

/* ---------- Detail ---------- */
.backlink { display: inline-block; color: var(--muted); text-decoration: none; font-size: 14px; margin-bottom: 14px; }
.backlink:hover { color: var(--brand); }
.kv { display: grid; grid-template-columns: 200px 1fr; gap: 10px 16px; margin: 0; }
.kv dt { color: var(--muted); font-size: 13px; }
.kv dd { margin: 0; font-size: 14px; }
.actions { display: flex; gap: 12px; flex-wrap: wrap; }
.actions form { margin: 0; }
code { background: var(--surface-2); border: 1px solid var(--border); padding: 1px 7px; border-radius: 6px; font-size: 13px; }

/* ---------- Login ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 500px at 50% -10%, #fff6ec, var(--canvas)); }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 20px; padding: 38px 34px; width: 100%; max-width: 380px; box-shadow: var(--shadow-lg); }
.brand-big { display: flex; align-items: center; justify-content: center; gap: 12px; font-size: 22px; font-weight: 700; }
.brand-logo-img { width: 40px; height: 40px; border-radius: 11px; object-fit: cover; box-shadow: var(--shadow-sm); }
.subtitle { text-align: center; color: var(--muted); margin: 8px 0 26px; font-size: 14px; }
.login-card label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 14px; font-weight: 500; }
.login-card input { width: 100%; padding: 11px 13px; margin-top: 6px; border: 1px solid var(--border-strong); border-radius: 10px; font-size: 15px; font-family: var(--font); transition: border-color .15s, box-shadow .15s; }
.login-card input:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(139, 94, 60, .12); }
.login-card .btn { width: 100%; justify-content: center; margin-top: 4px; }
.btn-google { width: 100%; justify-content: center; background: var(--surface); color: var(--text); border: 1px solid var(--border-strong); padding: 11px; border-radius: 10px; font-size: 15px; font-weight: 500; cursor: pointer; font-family: var(--font); display: inline-flex; align-items: center; gap: 10px; transition: background .15s; }
.btn-google:hover { background: var(--surface-2); }
.btn-google svg { width: 18px; height: 18px; }
.sep { text-align: center; color: var(--muted); margin: 20px 0; position: relative; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; }
.sep::before, .sep::after { content: ""; position: absolute; top: 50%; width: 38%; height: 1px; background: var(--border); }
.sep::before { left: 0; } .sep::after { right: 0; }
.error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f0cabf; padding: 11px 13px; border-radius: 10px; margin-bottom: 18px; font-size: 14px; }

/* ---------- Error page ---------- */
.error-page { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.error-card { max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: 36px; text-align: center; box-shadow: var(--shadow-md); }
.error-card .big { font-size: 40px; margin-bottom: 8px; }
.error-logo { width: 64px; height: 64px; border-radius: 16px; object-fit: cover; margin-bottom: 12px; box-shadow: var(--shadow-sm); }
.error-card .btn { margin-top: 18px; }

/* ---------- Responsive ---------- */
@media (max-width: 820px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 8px; padding: 12px 16px; }
  .sb-brand { padding: 0; }
  .sb-nav { flex-direction: row; flex-wrap: wrap; flex: 1; justify-content: center; }
  .sb-footer { border-top: none; padding-top: 0; }
  .sb-user { display: none; }
  .main-inner { padding: 24px 18px 48px; }
}
