:root {
  --bleu: #0b1f3a;
  --bleu-2: #12325a;
  --bleu-3: #1d3a5f;
  --accent: #2b6cb0;
  --accent-soft: #e7f0f9;
  --craie: #f4f5f7;
  --craie-2: #eaecef;
  --ligne: #dfe3e8;
  --noir: #12161c;
  --gris: #6a7480;
  --rouge: #c0392b;
  --rouge-soft: #fbeaea;
  --vert: #2e7d5b;
  --vert-soft: #e6f4ec;
  --ambre: #b7791f;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(11, 31, 58, 0.08), 0 1px 2px rgba(11, 31, 58, 0.06);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--noir);
  background: var(--craie);
  font-size: 14px;
  line-height: 1.45;
}
h1, h2, h3, h4 { margin: 0; font-weight: 650; }
a { color: var(--accent); }
[hidden] { display: none !important; }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 20% -10%, #17335c 0%, var(--bleu) 55%);
}
.login-card {
  width: 100%; max-width: 380px; background: #fff; border-radius: 16px;
  padding: 32px 28px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  display: flex; flex-direction: column; gap: 14px;
}
.login-logo {
  width: 60px; height: 60px; border: 2px dashed var(--ligne); border-radius: 10px;
  display: grid; place-items: center; color: var(--gris); font-size: 11px; letter-spacing: 1px;
  margin: 0 auto 4px;
}
.login-logo-img {
  display: block; max-width: 150px; max-height: 96px; width: auto; height: auto;
  margin: 0 auto 8px; object-fit: contain;
}
.brand-logo-img {
  width: 34px; height: 34px; border-radius: 8px; object-fit: contain;
  background: rgba(255, 255, 255, 0.12);
}
.login-card h1 { text-align: center; font-size: 20px; color: var(--bleu); line-height: 1.2; }
.login-card h1 span { display: block; font-size: 12px; color: var(--gris); font-weight: 500; margin-top: 2px; letter-spacing: .3px; }
.login-card label { display: flex; flex-direction: column; font-size: 12px; color: var(--gris); gap: 4px; }
.login-error { color: var(--rouge); font-size: 13px; margin: 0; text-align: center; }
.login-hint { font-size: 12px; color: var(--gris); }
.login-hint summary { cursor: pointer; }
.login-hint ul { margin: 8px 0 0; padding-left: 16px; }
.login-hint li { margin: 2px 0; }

/* ---------- Inputs & buttons ---------- */
input, select, textarea {
  font: inherit; padding: 9px 11px; border: 1px solid var(--ligne); border-radius: 8px;
  background: #fff; color: var(--noir); width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
label.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--gris); }

.btn {
  display: inline-flex; align-items: center; gap: 6px; justify-content: center;
  padding: 9px 14px; border-radius: 8px; border: 1px solid transparent; cursor: pointer;
  font: inherit; font-weight: 600; background: var(--craie-2); color: var(--noir);
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--bleu); color: #fff; }
.btn-accent { background: var(--accent); color: #fff; }
.btn-ghost { background: transparent; border-color: var(--ligne); color: var(--noir); }
.btn-danger { background: var(--rouge-soft); color: var(--rouge); border-color: #f0c9c4; }
.btn-sm { padding: 5px 10px; font-size: 12.5px; }
.btn-block { width: 100%; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; background: var(--bleu); color: #cdd8e6; display: flex; flex-direction: column;
  position: sticky; top: 0; height: 100vh;
}
.brand {
  padding: 18px 18px; font-weight: 700; color: #fff; display: flex; align-items: center; gap: 10px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08); font-size: 15px;
}
.brand-logo {
  background: rgba(255, 255, 255, 0.12); color: #fff; width: 34px; height: 34px; border-radius: 8px;
  display: grid; place-items: center; font-size: 12px; letter-spacing: .5px;
}
.nav { padding: 12px 10px; display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  color: #c2cfe0; text-decoration: none; padding: 10px 12px; border-radius: 8px; font-weight: 550;
  display: flex; align-items: center; gap: 10px;
}
.nav a:hover { background: rgba(255, 255, 255, 0.06); color: #fff; }
.nav a.active { background: var(--accent); color: #fff; }
.sidebar-user { padding: 14px; border-top: 1px solid rgba(255, 255, 255, 0.08); display: flex; flex-direction: column; gap: 8px; }
.user-name { color: #fff; font-weight: 600; font-size: 13px; }
/* Bouton de deconnexion : lisible sur le fond fonce de la barre laterale. */
.sidebar-user .btn-ghost { background: rgba(255, 255, 255, 0.12); border-color: rgba(255, 255, 255, 0.22); color: #fff; }
.sidebar-user .btn-ghost:hover { background: rgba(255, 255, 255, 0.22); }
#boot { color: #c2cfe0; }

.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 26px; background: #fff; border-bottom: 1px solid var(--ligne); position: sticky; top: 0; z-index: 5;
}
.topbar h2 { font-size: 18px; }
.view { padding: 24px 26px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11.5px; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
}
.badge.gray { background: var(--craie-2); color: var(--gris); }
.badge.green { background: var(--vert-soft); color: var(--vert); }
.badge.red { background: var(--rouge-soft); color: var(--rouge); }
.badge.amber { background: #fdf3e2; color: var(--ambre); }

/* ---------- Cards / grids ---------- */
.card { background: #fff; border: 1px solid var(--ligne); border-radius: var(--radius); box-shadow: var(--shadow); }
.card-pad { padding: 18px; }
.card h3 { font-size: 14px; margin-bottom: 12px; }
.grid { display: grid; gap: 16px; }
.grid-kpi { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.section-gap { margin-top: 20px; }

.kpi { padding: 16px 18px; }
.kpi .kpi-label { color: var(--gris); font-size: 12px; text-transform: uppercase; letter-spacing: .4px; }
.kpi .kpi-value { font-size: 24px; font-weight: 700; margin-top: 6px; color: var(--bleu); }
.kpi .kpi-sub { font-size: 12px; color: var(--gris); margin-top: 2px; }

.chart-box { position: relative; height: 260px; }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--ligne); font-size: 13.5px; }
th { color: var(--gris); font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; font-weight: 600; }
tbody tr:hover { background: var(--craie); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }

.toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.toolbar .grow { flex: 1; }

.money-pos { color: var(--vert); font-weight: 600; }
.money-neg { color: var(--rouge); font-weight: 600; }
.muted { color: var(--gris); }
.chips { display: flex; flex-wrap: wrap; gap: 4px; }
.chip { background: var(--craie-2); border-radius: 6px; padding: 2px 8px; font-size: 11.5px; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(11, 22, 40, 0.55); display: grid; place-items: center;
  padding: 20px; z-index: 50;
}
.modal {
  background: #fff; border-radius: 14px; width: 100%; max-width: 560px; max-height: 90vh; overflow: auto;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.4);
}
.modal.wide { max-width: 920px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--ligne); position: sticky; top: 0; background: #fff; }
.modal-head h3 { font-size: 16px; }
.modal-body { padding: 20px; display: flex; flex-direction: column; gap: 14px; }
.modal-foot { padding: 14px 20px; border-top: 1px solid var(--ligne); display: flex; justify-content: flex-end; gap: 8px; position: sticky; bottom: 0; background: #fff; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 20px; color: var(--gris); line-height: 1; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.checks { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; max-height: 160px; overflow: auto; border: 1px solid var(--ligne); border-radius: 8px; padding: 10px; }
.checks label { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--noir); }
.checks input { width: auto; }
.assignment-list { display: grid; gap: 8px; border: 1px solid var(--ligne); border-radius: 8px; padding: 10px; }
.assignment-row { display: grid; grid-template-columns: minmax(160px, 1fr) minmax(180px, 1fr) auto; gap: 8px; align-items: center; }
/* Choix du departement principal : masque tant qu'une seule affectation est
   cochee (visibility, pas display, pour que les colonnes restent alignees). */
.a-primary-cell { display: flex; align-items: center; gap: 6px; white-space: nowrap; font-size: 12px; }
.a-primary-cell input { width: auto; }
.assignment-row label { display: flex; gap: 8px; align-items: center; color: var(--noir); font-size: 13px; }
.assignment-row input { width: auto; }
.tabs { display: flex; gap: 6px; margin-bottom: 12px; border-bottom: 1px solid var(--ligne); }
.tab { background: transparent; border: 0; border-bottom: 2px solid transparent; padding: 10px 12px; cursor: pointer; color: var(--gris); font-weight: 650; }
.tab.active { color: var(--bleu); border-bottom-color: var(--accent); }

.pdf-frame { width: 100%; height: 72vh; border: 1px solid var(--ligne); border-radius: 8px; }

/* ---------- Recherche avec autocompletion ----------
   Le champ garde sa place dans le flux, la liste flotte au-dessus : sans
   position absolue, chaque frappe deplacait le reste du formulaire. */
.autocomplete { position: relative; }
.autocomplete-list {
  position: absolute; left: 0; right: 0; top: 100%; z-index: 20;
  background: #fff; border: 1px solid var(--ligne); border-radius: 8px;
  box-shadow: var(--shadow); max-height: 240px; overflow: auto; margin-top: 4px;
}
.autocomplete-item { padding: 8px 11px; cursor: pointer; font-size: 13.5px; border-bottom: 1px solid var(--craie-2); }
.autocomplete-item:last-child { border-bottom: 0; }
.autocomplete-item:hover, .autocomplete-item.active { background: var(--craie); }
.autocomplete-item .muted { font-size: 12px; }
.autocomplete-empty { padding: 8px 11px; font-size: 13px; color: var(--gris); }

/* Retenue builder rows */
.retenue-row { display: grid; grid-template-columns: 1.4fr 0.9fr 0.8fr auto; gap: 8px; align-items: end; }
.summary-box { background: var(--craie); border: 1px solid var(--ligne); border-radius: 8px; padding: 14px; }
.summary-line { display: flex; justify-content: space-between; padding: 3px 0; }
.summary-line.total { border-top: 1px solid var(--ligne); margin-top: 6px; padding-top: 8px; font-weight: 700; font-size: 15px; }

/* ---------- Toast ---------- */
#toast-root { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast {
  background: var(--noir); color: #fff; padding: 11px 15px; border-radius: 8px; font-size: 13px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .3); max-width: 340px; animation: slidein .18s ease;
}
.toast.ok { background: var(--vert); }
.toast.err { background: var(--rouge); }
@keyframes slidein { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

.empty { text-align: center; color: var(--gris); padding: 40px 16px; }

@media (max-width: 720px) {
  .assignment-row { grid-template-columns: 1fr; }
}

/* En-tetes de colonnes triables (liste du personnel) */
.th-sort { cursor: pointer; user-select: none; white-space: nowrap; }
.th-sort:hover { color: var(--bleu); }
.th-sort-on { color: var(--accent); }

/* Bandeau de notification (factures a regler dans la vue departement) */
.notice { border-radius: 8px; padding: 10px 12px; font-size: 13px; border: 1px solid transparent; margin: 8px 0; }
.notice-warn { background: #fdf3e2; border-color: #f0d9ae; color: var(--ambre); }

/* Tableau compact de saisie (lignes de facturation) */
.mini-table th, .mini-table td { padding: 6px 8px; }
.mini-table input { width: 100%; }
.mini-table tfoot td { border-bottom: 0; }
