:root {
  --bleu: #0d3b66;
  --bleu-clair: #1b6ca8;
  --gris: #f4f6f8;
  --fond-carte: #ffffff;
  --texte: #1b1f24;
  --texte-doux: #4a5560;
  --bord: #d8dee6;
  --rouge: #b3261e;
  --vert: #1e7a44;
  --entete-tableau: #eef2f6;
  --groupe-tableau: #e2eaf2;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--gris);
  color: var(--texte);
}

/* ---------- Barre de navigation ---------- */
.topbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 1rem;
  background: var(--bleu); color: #fff; padding: .8rem 1.2rem;
}
.brand { font-weight: 700; font-size: 1.1rem; }
.topbar nav { display: flex; flex-wrap: wrap; align-items: center; gap: .9rem; margin-left: auto; }
.topbar a { color: #fff; text-decoration: none; font-size: .95rem; }
.topbar a:hover { text-decoration: underline; }
.topbar .who { opacity: .8; font-size: .85rem; }
.btn-out { border: 1px solid rgba(255,255,255,.6); padding: .25rem .6rem; border-radius: 4px; }
/* Case technique du menu mobile : invisible, mais activable par son label. */
.nav-toggle {
  position: fixed !important;
  left: -10000px !important;
  top: auto !important;
  width: 1px !important;
  height: 1px !important;
  margin: 0 !important;
  padding: 0 !important;
  opacity: 0 !important;
  overflow: hidden !important;
  pointer-events: none !important;
  appearance: none !important;
  -webkit-appearance: none !important;
}
.nav-burger { display: none; }

/* ---------- Structure ---------- */
main { max-width: 1100px; margin: 1.5rem auto; padding: 0 1rem; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .8rem; }
.card {
  background: var(--fond-carte); border: 1px solid var(--bord); border-radius: 8px;
  padding: 1rem 1.2rem; margin-bottom: 1.2rem; overflow-x: auto;
}
.card.narrow { max-width: 460px; margin-left: auto; margin-right: auto; }
.card.account-card { margin: 0 auto 1.2rem; }
.page-title {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.page-title h1 { margin: 0; }
.version {
  color: #5f6b76; background: #e9eef3; border: 1px solid var(--bord);
  border-radius: 999px; padding: .25rem .6rem; font-size: .78rem; white-space: nowrap;
}

/* ---------- Formulaires ---------- */
form.row { display: flex; flex-wrap: wrap; gap: 1rem; align-items: flex-end; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 1rem; }
.card.account-card form { display: grid; gap: .9rem; }
label { display: block; font-size: .85rem; color: var(--texte-doux); }
label.check { display: flex; align-items: center; gap: .35rem; font-size: .85rem; }
input, select {
  display: block; width: 100%; margin-top: .25rem; padding: .5rem .55rem;
  border: 1px solid var(--bord); border-radius: 5px; font-size: 1rem;
  background: var(--fond-carte); color: var(--texte);
}
label.check input { width: auto; margin: 0; }
fieldset {
  border: 1px solid var(--bord); border-radius: 6px;
  padding: .9rem 1rem 1.1rem; margin: 1.2rem 0;
}
legend { font-size: .85rem; color: var(--texte-doux); padding: 0 .35rem; }
button {
  background: var(--bleu-clair); color: #fff; border: 0; border-radius: 5px;
  padding: .55rem .9rem; font-size: .92rem; cursor: pointer; min-height: 40px;
}
button:hover { background: var(--bleu); }
button.danger { background: var(--rouge); }
button[disabled] { opacity: .5; cursor: not-allowed; }
.actions { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; margin-top: .4rem; }
.btn-link { color: var(--bleu-clair); text-decoration: none; font-size: .9rem; }
.btn-link:hover { text-decoration: underline; }
form.inline { display: inline; }
form.inline-row { display: flex; gap: .5rem; align-items: center; flex-wrap: wrap; }
form.inline-row input { width: auto; min-width: 150px; margin: 0; }

/* ---------- Tableaux ---------- */
table { width: 100%; border-collapse: collapse; margin-top: .8rem; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--bord); font-size: .92rem; vertical-align: middle; }
th { background: var(--entete-tableau); font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; }
th.grp {
  text-align: center; background: var(--groupe-tableau);
  border-left: 1px solid var(--bord); border-right: 1px solid var(--bord);
}
th.sub { font-size: .72rem; background: var(--entete-tableau); white-space: nowrap; }
tr:hover td { background: rgba(0,0,0,.02); }
td.nowrap { white-space: nowrap; }
td.empty { text-align: center; color: #78838f; font-style: italic; }
td.val { font-variant-numeric: tabular-nums; font-weight: 600; }

/* ---------- Divers ---------- */
.flash { padding: .6rem .8rem; border-radius: 6px; margin-bottom: 1rem; font-size: .92rem; }
.flash.ok { background: #e6f4ea; color: var(--vert); border: 1px solid #b7e0c4; }
.flash.err { background: #fdeceb; color: var(--rouge); border: 1px solid #f3c2bf; }
.flash.warn { background: #fff8e1; color: #8a6100; border: 1px solid #f0dca0; }
.hint { font-size: .82rem; color: #6b7682; line-height: 1.5; }
.tag { background: var(--bleu-clair); color: #fff; border-radius: 3px; padding: 0 .35rem; font-size: .7rem; white-space: nowrap; }
.tag.warn-tag { background: #8a6100; }
pre.sortie {
  background: #11161d; color: #e6edf3; padding: .8rem; border-radius: 6px;
  overflow-x: auto; font-size: .82rem; white-space: pre-wrap; word-break: break-word;
}
.foot { text-align: center; color: #8b949e; font-size: .8rem; padding: 1.5rem 0; }

/* ---------- Theme fonce (preference par utilisateur) ---------- */
body.theme-dark {
  --bleu: #101b2b;
  --bleu-clair: #4da3e6;
  --gris: #121820;
  --fond-carte: #1d2631;
  --texte: #e7edf4;
  --texte-doux: #bdc8d4;
  --bord: #3b4654;
  --rouge: #ef6b64;
  --vert: #70d49a;
  --entete-tableau: #283442;
  --groupe-tableau: #324154;
  color-scheme: dark;
}
body.theme-dark .topbar { background: #0b111a; }
body.theme-dark input,
body.theme-dark select { background: #121922; color: #eef3f8; }
body.theme-dark tr:hover td { background: rgba(255,255,255,.04); }
body.theme-dark .hint,
body.theme-dark .foot,
body.theme-dark td.empty { color: #aab6c2; }
body.theme-dark .version { color: #d4dce5; background: #263342; border-color: var(--bord); }
body.theme-dark .flash.ok { background: #173826; border-color: #286744; }
body.theme-dark .flash.err { background: #482321; border-color: #7a3834; }
body.theme-dark .flash.warn { color: #ffe39a; background: #443716; border-color: #786326; }

/* ---------- Tablette ---------- */
@media (max-width: 900px) {
  main { margin: 1rem auto; }
  form.row { gap: .75rem; }
  form.row label { flex: 1 1 200px; }
}

/* ---------- Smartphone ---------- */
@media (max-width: 680px) {
  /* Menu replie derriere un bouton, sans JavaScript */
  .topbar { padding: .7rem .9rem; gap: .6rem; }
  .brand { font-size: 1rem; flex: 1 1 auto; }
  .nav-burger {
    display: block; font-size: 1.5rem; line-height: 1;
    cursor: pointer; padding: .1rem .45rem;
    border: 1px solid rgba(255,255,255,.6); border-radius: 5px; color: #fff;
  }
  .topbar nav {
    display: none; flex-direction: column; align-items: stretch;
    width: 100%; margin-left: 0; gap: 0;
  }
  .nav-toggle:checked ~ nav { display: flex; }
  .topbar nav a, .topbar nav .who {
    padding: .7rem .2rem; border-top: 1px solid rgba(255,255,255,.18);
  }
  .btn-out { border: 0; text-align: left; }

  main { padding: 0 .7rem; }
  h1 { font-size: 1.25rem; }
  .card { padding: .9rem .8rem; border-radius: 6px; }
  .card.narrow { max-width: none; }
  .page-title { gap: .5rem; }

  /* Formulaires en pleine largeur, plus faciles au doigt */
  form.row { flex-direction: column; align-items: stretch; }
  form.row label, .grid2 { width: 100%; }
  .grid2 { grid-template-columns: 1fr; }
  form.inline-row { flex-direction: column; align-items: stretch; }
  form.inline-row input { width: 100%; min-width: 0; }
  .actions { flex-direction: column; align-items: stretch; }
  .actions button, form.row button, form.inline-row button { width: 100%; }
  input, select { font-size: 1rem; padding: .6rem .55rem; }

  /* Tableaux convertis en fiches empilees */
  table.responsive { border: 0; margin-top: .6rem; }
  table.responsive thead { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
  table.responsive tr {
    display: block; border: 1px solid var(--bord); border-radius: 6px;
    padding: .5rem .65rem; margin-bottom: .7rem; background: var(--fond-carte);
  }
  table.responsive td {
    display: flex; justify-content: space-between; align-items: baseline; gap: .8rem;
    border: 0; border-bottom: 1px dashed var(--bord); padding: .4rem 0; text-align: right;
  }
  table.responsive td:last-child { border-bottom: 0; }
  table.responsive td::before {
    content: attr(data-label);
    font-size: .74rem; text-transform: uppercase; letter-spacing: .03em;
    color: var(--texte-doux); text-align: left; flex: 0 0 45%;
  }
  table.responsive td[data-label="Actions"],
  table.responsive td[data-label="Compte"] { flex-direction: column; align-items: stretch; text-align: left; }
  table.responsive td[data-label="Actions"]::before,
  table.responsive td[data-label="Compte"]::before { flex: none; margin-bottom: .35rem; }
  table.responsive td[data-label="Actions"] form.inline { display: block; margin-top: .4rem; }
  table.responsive td[data-label="Actions"] button { width: 100%; }
  table.responsive td.empty { display: block; text-align: center; }
  table.responsive td.empty::before { content: none; }
  table.responsive tr:hover td { background: transparent; }
  table.responsive td.nowrap { white-space: normal; }
}
