:root {
  --fond: #f6f7f9;
  --surface: #ffffff;
  --texte: #1c2024;
  --texte-doux: #5f6b76;
  --bordure: #dde1e6;
  --accent: #1f6feb;
  --accent-texte: #ffffff;
  --survol: #eef3fb;
  --danger: #c62828;
  --rayon: 8px;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #111418;
    --surface: #1a1e23;
    --texte: #e6e9ec;
    --texte-doux: #9aa5b1;
    --bordure: #2d333b;
    --accent: #4c8dff;
    --accent-texte: #0b0f14;
    --survol: #222a35;
    --danger: #ff6b6b;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond);
  color: var(--texte);
}

header {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--bordure);
}
header h1 { margin: 0; font-size: 18px; }
#usager { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; color: var(--texte-doux); }

main { padding: 16px; max-width: 1400px; margin: 0 auto; }

button, input, select, textarea { font: inherit; color: inherit; }

button {
  padding: 7px 14px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--surface);
  cursor: pointer;
}
button:hover { background: var(--survol); }
button.principal { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }
button.principal:hover { filter: brightness(1.08); }
button.danger { color: var(--danger); border-color: var(--danger); }
button.discret { border: none; background: none; padding: 4px 6px; text-decoration: underline; }
button:disabled { opacity: .6; cursor: wait; }

input, select, textarea {
  width: 100%;
  padding: 7px 10px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--fond);
}

label { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-weight: 500; }
label.case { flex-direction: row; align-items: center; gap: 8px; }
label.case input { width: auto; }

.carte {
  max-width: 380px;
  margin: 48px auto;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
}
.carte h2 { margin-top: 0; }
.carte button { width: 100%; }

.separateur { display: flex; align-items: center; gap: 8px; color: var(--texte-doux); font-size: 13px; margin: 14px 0; }
.separateur::before, .separateur::after { content: ""; flex: 1; border-top: 1px solid var(--bordure); }

.erreur { color: var(--danger); min-height: 1em; margin: 8px 0; }
.aide, .meta { color: var(--texte-doux); font-size: 13px; }

#onglets { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 12px; }
.choix-table { flex-direction: row; align-items: center; gap: 8px; margin: 0; }
.choix-table select { width: auto; min-width: 260px; max-width: 100%; background: var(--surface); }

th.triable { cursor: pointer; user-select: none; }
th.triable:hover { color: var(--texte); }
th.nombre { text-align: right; }
#tableau[aria-busy="true"] tbody { opacity: .5; }

.pagination { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; color: var(--texte-doux); }
#onglets button.actif { background: var(--accent); border-color: var(--accent); color: var(--accent-texte); }

.barre { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-bottom: 12px; }
.barre input { flex: 1 1 220px; width: auto; background: var(--surface); }
#compte { color: var(--texte-doux); }

.tableau-conteneur {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
}
table { width: 100%; border-collapse: collapse; }
th, td { padding: 8px 12px; text-align: left; border-bottom: 1px solid var(--bordure); white-space: nowrap; }
td { max-width: 360px; overflow: hidden; text-overflow: ellipsis; }
td.nombre { text-align: right; font-variant-numeric: tabular-nums; }
th { position: sticky; top: 0; background: var(--surface); font-size: 13px; color: var(--texte-doux); }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--survol); }

dialog {
  width: min(560px, calc(100vw - 32px));
  padding: 24px;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--surface);
  color: var(--texte);
}
dialog::backdrop { background: rgb(0 0 0 / .4); }
dialog h2 { margin-top: 0; }
.actions { display: flex; gap: 8px; margin-top: 8px; }
.espace { flex: 1; }

#toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(20px);
  max-width: calc(100vw - 32px);
  padding: 10px 18px;
  border-radius: var(--rayon);
  background: var(--texte);
  color: var(--fond);
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.visible { opacity: 1; transform: translateX(-50%); }
#toast.erreur { background: var(--danger); color: #fff; }

[hidden] { display: none !important; }
