:root {
  --bg: #f4f6f9;
  --card: #ffffff;
  --ink: #171b21;
  --muted: #6b7480;
  --line: #e4e7ec;
  --brand: #1f6feb;
  --brand-dark: #1447a8;
  --brand-soft: #e8f0fe;
  --ok: #1a7f45;
  --warn: #b26a00;
  --danger: #c0392b;
  --side: #0f1520;
  --side-hover: #182130;
  --side-active: #1c2637;
  --side-ink: #c2ccdb;
  --side-line: #1e2836;
  --sidebar-w: 252px;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }

/* ---------- structure : barre latérale + contenu ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}
.sidebar {
  background: var(--side); color: var(--side-ink);
  display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh; overflow-y: auto;
  padding: 1rem .7rem;
}
.brand { display: flex; align-items: center; gap: .6rem; padding: .3rem .5rem 1.1rem; }
.brand-mark {
  width: 32px; height: 32px; flex: 0 0 auto; border-radius: 9px;
  background: linear-gradient(135deg, #3079f7, #1b48c9);
  color: #fff; display: grid; place-items: center; font-size: 16px;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.18; min-width: 0; }
.brand-text strong { color: #fff; font-size: .95rem; }
.brand-text small { color: #7b879a; font-size: .72rem; }

.nav { display: flex; flex-direction: column; gap: .1rem; flex: 1; }
.nav-group {
  margin: 1.05rem .6rem .35rem; font-size: .68rem; letter-spacing: .09em;
  text-transform: uppercase; color: #667287; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: .65rem;
  padding: .5rem .6rem; border-radius: 8px; border-left: 2px solid transparent;
  color: var(--side-ink); font-size: .92rem;
}
.nav-item:hover { background: var(--side-hover); color: #fff; text-decoration: none; }
.nav-item.active { background: var(--side-active); color: #fff; font-weight: 600; border-left-color: var(--brand); }
.nav-item .ico { flex: 0 0 auto; opacity: .8; }
.nav-item.active .ico { opacity: 1; color: #7fb0ff; }
.nav-label { min-width: 0; }
.nav-badge { margin-left: auto; }

.sidebar-foot {
  margin-top: .6rem; padding-top: .75rem; border-top: 1px solid var(--side-line);
  display: flex; flex-direction: column; gap: .45rem;
}
.who { display: flex; align-items: center; gap: .55rem; padding: .3rem .5rem; }
.avatar {
  width: 30px; height: 30px; flex: 0 0 auto; border-radius: 50%;
  background: #263248; color: #dbe6f7; display: grid; place-items: center;
  font-size: .82rem; font-weight: 700;
}
.who-text { display: flex; flex-direction: column; line-height: 1.18; min-width: 0; }
.who-text strong { color: #fff; font-size: .88rem; }
.who-text small { color: #75839a; font-size: .74rem; }
.btn-logout {
  display: flex; align-items: center; gap: .5rem; width: 100%;
  background: none; border: 0; color: var(--side-ink); cursor: pointer;
  padding: .45rem .6rem; border-radius: 8px; font: inherit; font-size: .88rem; text-align: left;
}
.btn-logout:hover { background: var(--side-hover); color: #fff; }
.version { margin: .15rem .6rem 0; color: #5d6879; font-size: .7rem; }

.content { display: flex; flex-direction: column; min-width: 0; }
main { flex: 1; min-width: 0; padding: 1.4rem 1.6rem; }
footer { padding: 0 1.6rem 2rem; }
.mobile-bar { display: none; }

/* ---------- composants ---------- */
.small { font-size: .82rem; }
.muted { color: var(--muted); }
.ok-text { color: var(--ok); }
.warn-text { color: var(--warn); }

.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 1rem 1.1rem; margin-bottom: 1.1rem; overflow-x: auto;
}
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; }

.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: .8rem; margin-bottom: 1.1rem; }
.kpi {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: .7rem .85rem; display: flex; flex-direction: column; gap: .15rem;
}
.kpi .k-label { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
.kpi .k-value { font-size: 1.22rem; font-weight: 650; }

table { width: 100%; border-collapse: collapse; }
th, td { padding: .5rem .55rem; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
tr.row-pending { background: #fff9ec; }
tr.row-alert { background: #fdf1f0; font-weight: 600; }
.actions-cell { display: flex; flex-wrap: wrap; gap: .3rem; }

.pill {
  display: inline-block; padding: .05rem .5rem; border-radius: 999px;
  font-size: .78rem; background: #eef1f5; color: #46505d; white-space: nowrap;
}
.pill.ok, .status-paye, .status-valide { background: #e4f6ea; color: var(--ok); }
.pill.warn, .status-partiel, .status-en_attente { background: #fdf3e2; color: var(--warn); }
.pill.danger, .status-en_retard, .status-rejete { background: #fdecea; color: var(--danger); }
.status-a_payer { background: #eef1f5; color: #46505d; }

.button, button.primary, button.button {
  display: inline-block; border: 1px solid var(--line); background: #fff; color: var(--ink);
  padding: .38rem .7rem; border-radius: 8px; cursor: pointer; font-size: .88rem;
}
button.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
button.ok { border-color: #bfe3cb; color: var(--ok); }
button.danger { border-color: #f0c8c3; color: var(--danger); }
.button.small, button.small { padding: .22rem .5rem; font-size: .8rem; }
button:disabled, input:disabled { opacity: .45; cursor: not-allowed; }
form.inline { display: inline; }

.form label { display: block; margin-bottom: .7rem; font-size: .88rem; color: #39414c; }
.form input, .form select, .form textarea, .filters input, .filters select, .row-form input, td input {
  font: inherit; padding: .35rem .5rem; border: 1px solid var(--line); border-radius: 7px; background: #fff;
}
.form .row { display: flex; gap: .8rem; flex-wrap: wrap; }
.form .row > label { flex: 1 1 220px; }
.form .actions { display: flex; gap: .6rem; }
.row-form { display: flex; gap: .35rem; align-items: center; flex-wrap: wrap; }
.row-form.tight { margin: 0; }
.row-form label { margin: 0; display: flex; gap: .3rem; align-items: center; font-size: .85rem; }
.filters { display: flex; gap: .7rem; flex-wrap: wrap; align-items: flex-end; }
.filters label { display: flex; flex-direction: column; font-size: .8rem; color: var(--muted); gap: .2rem; }

.flash { padding: .6rem .8rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.flash.ok { background: #e9f7ee; border-color: #bfe3cb; color: #14532d; }
.flash.err { background: #fdecea; border-color: #f0c8c3; color: #7a2318; }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { padding: .45rem 0; border-bottom: 1px dashed var(--line); display: flex; gap: .7rem; flex-wrap: wrap; }
.timeline .when { color: var(--muted); font-size: .82rem; min-width: 132px; }
.timeline .what { flex: 1 1 320px; }

.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.login { width: 380px; }
.login h1 { font-size: 1.25rem; }
.login label { display: block; margin-bottom: .8rem; font-size: .9rem; }
.login input { width: 100%; font: inherit; padding: .45rem .55rem; border: 1px solid var(--line); border-radius: 8px; }
.login button.primary { width: 100%; padding: .5rem; }

code { background: #eef1f5; padding: .05rem .3rem; border-radius: 5px; }

/* modification d'un compte, dépliée depuis le tableau des paramètres */
details.edit-user { display: inline-block; }
details.edit-user summary { display: inline-block; cursor: pointer; list-style: none; }
details.edit-user summary::-webkit-details-marker { display: none; }
details.edit-user[open] { display: block; min-width: 340px; }
details.edit-user .edit-form {
  margin: .6rem 0 .4rem; padding: .7rem .8rem;
  border: 1px solid var(--line); border-radius: 8px; background: #fafbfd;
}
details.edit-user .edit-form .row > label { flex: 1 1 150px; }
details.edit-user .edit-form input, details.edit-user .edit-form select { width: 100%; }

/* ---------- écrans étroits : la barre latérale se replie ---------- */
.backdrop { display: none; }
@media (max-width: 900px) {
  .shell { grid-template-columns: minmax(0, 1fr); }
  .sidebar {
    position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w); height: 100vh;
    transform: translateX(-102%); transition: transform .18s ease;
    z-index: 40; box-shadow: 0 0 40px rgba(6, 10, 18, .45);
  }
  .nav-toggle:checked ~ .shell .sidebar { transform: none; }
  .nav-toggle:checked ~ .shell .backdrop {
    display: block; position: fixed; inset: 0; z-index: 30; background: rgba(8, 12, 20, .5);
  }
  .mobile-bar {
    display: flex; align-items: center; gap: .7rem;
    padding: .7rem 1rem; background: var(--side); color: #fff;
    position: sticky; top: 0; z-index: 20;
  }
  .burger { font-size: 1.3rem; line-height: 1; cursor: pointer; }
  .mobile-title { font-weight: 600; font-size: .95rem; }
  main { padding: 1rem; }
  footer { padding: 0 1rem 1.5rem; }
  th, td { padding: .4rem .35rem; font-size: .88rem; }
}
