/* ==========================================================================
   CRM BOG — feuille de style unique (self-hostée, zéro CDN).
   Tokens issus de docs/05-UI-UX.md. Cibles tactiles >= 44px, contrastes AA.
   ========================================================================== */

:root {
  --navy: #14182e;
  --navy-clair: #232946;
  --blue: #1376bb;
  --blue-sombre: #0f5d93;
  --sky: #abdafc;
  --red: #ee3f61;
  --green: #21a67a;
  --amber: #e8a13a;
  --violet: #7b61ff;

  --ink: #14182e;
  --muted: #5b6577;
  --line: #e6ebf2;
  --bg: #f4f7fb;
  --card: #ffffff;

  --rayon: 16px;
  --rayon-sm: 10px;
  --rayon-pill: 999px;
  --ombre: 0 1px 2px rgba(20, 24, 46, 0.04), 0 8px 24px rgba(20, 24, 46, 0.06);
  --ombre-forte: 0 12px 32px rgba(20, 24, 46, 0.14);
  --sidebar-l: 248px;
  --topbar-h: 72px;
  --cible: 44px;
  --transition: 140ms ease;
}

*,
*::before,
*::after { box-sizing: border-box; }

[x-cloak] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; letter-spacing: -0.01em; line-height: 1.25; }
h1 { font-size: 1.375rem; font-weight: 800; }
h2 { font-size: 1.05rem; font-weight: 700; }
h3 { font-size: 0.95rem; font-weight: 700; }
p { margin: 0; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }

:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 2px;
  border-radius: 4px;
}

.lien-evitement {
  position: absolute;
  left: -9999px;
  top: 0;
  background: var(--navy);
  color: #fff;
  padding: 12px 18px;
  z-index: 100;
  border-radius: 0 0 var(--rayon-sm) 0;
}
.lien-evitement:focus { left: 0; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ---------------------------------------------------------------- layout -- */
.appli { min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-l);
  background: var(--navy);
  color: #d7dcec;
  display: flex;
  flex-direction: column;
  padding: 18px 12px;
  gap: 6px;
  z-index: 40;
}

.sidebar__marque {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 16px;
  color: #fff;
}
.sidebar__logo {
  width: 36px; height: 36px;
  flex: 0 0 36px;
  border-radius: 10px;
  background: linear-gradient(140deg, var(--blue), var(--sky));
  color: var(--navy);
  display: grid; place-items: center;
  font-weight: 800; font-size: 0.85rem;
}
.sidebar__titre { font-size: 0.95rem; font-weight: 800; letter-spacing: -0.01em; }
.sidebar__sous-titre { font-size: 0.7rem; color: #8f9bbb; }

.sidebar__nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar__section-bas { margin-top: auto; padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.08); }

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: var(--cible);
  padding: 0 12px;
  border-radius: var(--rayon-sm);
  color: #c3cbe2;
  font-weight: 600;
  font-size: 0.9rem;
  transition: background var(--transition), color var(--transition);
}
.nav-item:hover { background: rgba(255, 255, 255, 0.08); color: #fff; text-decoration: none; }
.nav-item[aria-current="page"] { background: var(--blue); color: #fff; }
.nav-item__icone { width: 20px; height: 20px; flex: 0 0 20px; }
.nav-item__libelle { flex: 1; }

.badge-compteur {
  min-width: 22px;
  height: 22px;
  padding: 0 7px;
  border-radius: var(--rayon-pill);
  background: var(--red);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 800;
  display: inline-grid;
  place-items: center;
}

.sidebar__utilisateur {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; margin-top: 8px;
  border-radius: var(--rayon-sm);
  background: rgba(255, 255, 255, 0.06);
}
.avatar {
  width: 32px; height: 32px; flex: 0 0 32px;
  border-radius: 50%;
  background: var(--sky); color: var(--navy);
  display: grid; place-items: center;
  font-weight: 800; font-size: 0.78rem;
}
.sidebar__utilisateur .btn {
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.18);
  color: #fff;
}
.sidebar__utilisateur .btn:hover { background: rgba(255, 255, 255, 0.22); }
.sidebar__utilisateur-nom { font-size: 0.82rem; font-weight: 700; color: #fff; }
.sidebar__utilisateur-role { font-size: 0.68rem; color: #8f9bbb; text-transform: uppercase; letter-spacing: 0.04em; }

.contenu { margin-left: var(--sidebar-l); min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 16px;
  min-height: var(--topbar-h);
  padding: 12px 24px;
  background: rgba(244, 247, 251, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.topbar__titres { flex: 1; min-width: 0; }
.topbar__sous-titre { color: var(--muted); font-size: 0.85rem; }
.topbar__actions { display: flex; align-items: center; gap: 10px; }

.recherche { position: relative; }
.recherche input {
  height: var(--cible);
  width: 260px;
  max-width: 40vw;
  padding: 0 14px 0 38px;
  border: 1px solid var(--line);
  border-radius: var(--rayon-pill);
  background: var(--card);
  color: var(--ink);
  font-size: 0.9rem;
}
.recherche input::placeholder { color: var(--muted); }
.recherche__icone {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 18px; height: 18px; color: var(--muted); pointer-events: none;
}

.page { padding: 24px; flex: 1; }
.page > * + * { margin-top: 20px; }

/* --------------------------------------------------------------- cartes --- */
.carte {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 18px;
}
.carte__entete {
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px; margin-bottom: 14px;
}

.grille { display: grid; gap: 16px; }
.grille--kpi { grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); }
.grille--2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }

/* ------------------------------------------------------------ tuiles KPI -- */
.tuile {
  display: flex; align-items: center; gap: 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 16px;
  color: inherit;
}
a.tuile:hover { text-decoration: none; box-shadow: var(--ombre-forte); }
.tuile__icone {
  width: 44px; height: 44px; flex: 0 0 44px;
  border-radius: 50%;
  display: grid; place-items: center;
  background: var(--sky); color: var(--navy);
}
.tuile__icone--bleu { background: #e2f0fb; color: var(--blue); }
.tuile__icone--vert { background: #dcf3ea; color: #157a58; }
.tuile__icone--rouge { background: #fde2e7; color: #c32744; }
.tuile__icone--ambre { background: #fbeed8; color: #9a6510; }
.tuile__icone--navy { background: #e1e3ec; color: var(--navy); }
.tuile__valeur { font-size: 1.6rem; font-weight: 800; line-height: 1.1; }
.tuile__libelle { color: var(--muted); font-size: 0.82rem; }
.tuile__delta { font-size: 0.75rem; font-weight: 700; }
.tuile__delta--hausse { color: #157a58; }
.tuile__delta--baisse { color: #c32744; }

/* -------------------------------------------------------------- badges ---- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px;
  border-radius: var(--rayon-pill);
  font-size: 0.74rem; font-weight: 700;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.badge--import { background: #e2f0fb; color: #0d5182; }
.badge--local { background: #dcf3ea; color: #12664a; }
.badge--carte-grise { background: #ece7ff; color: #4b31b5; }
.badge--en-cours { background: #fbeed8; color: #8a5a0c; }
.badge--valide { background: #dcf3ea; color: #12664a; }
.badge--perdu { background: #fde2e7; color: #ad1f3c; }
.badge--livre { background: #e1e3ec; color: var(--navy); }
.badge--neutre { background: #eef2f8; color: var(--muted); }
.badge--retard { background: #fde2e7; color: #ad1f3c; }
.badge--aujourdhui { background: #fbeed8; color: #8a5a0c; }

/* --------------------------------------------------------- progression ---- */
.progression { display: flex; align-items: center; gap: 10px; }
.progression__piste {
  flex: 1; height: 8px;
  background: var(--line);
  border-radius: var(--rayon-pill);
  overflow: hidden;
}
.progression__barre {
  height: 100%;
  border-radius: var(--rayon-pill);
  background: var(--blue);
  transition: width var(--transition);
}
.progression__barre--faible { background: var(--red); }
.progression__barre--moyenne { background: var(--amber); }
.progression__barre--forte { background: var(--green); }
.progression__valeur { font-size: 0.78rem; font-weight: 700; color: var(--muted); min-width: 38px; text-align: right; }

/* ------------------------------------------------------------ timeline ---- */
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline__etape {
  position: relative;
  padding: 0 0 18px 30px;
  border-left: 2px solid var(--line);
  margin-left: 9px;
}
.timeline__etape:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline__puce {
  position: absolute; left: -10px; top: 0;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--card);
  border: 2px solid var(--line);
  display: grid; place-items: center;
  color: #fff; font-size: 10px; font-weight: 800;
}
.timeline__etape--termine .timeline__puce { background: var(--green); border-color: var(--green); }
.timeline__etape--termine { border-left-color: var(--green); }
.timeline__etape--en-cours .timeline__puce {
  background: var(--blue); border-color: var(--blue);
  box-shadow: 0 0 0 4px rgba(19, 118, 187, 0.18);
}
.timeline__libelle { font-weight: 600; font-size: 0.9rem; }
.timeline__meta { color: var(--muted); font-size: 0.78rem; }

/* -------------------------------------------------------------- listes ---- */
.liste { list-style: none; margin: 0; padding: 0; }
.liste > li + li { border-top: 1px solid var(--line); }
.ligne {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 4px;
  min-height: var(--cible);
}
.ligne__principal { flex: 1; min-width: 0; }
.ligne__titre { font-weight: 700; font-size: 0.9rem; }
.ligne__meta { color: var(--muted); font-size: 0.8rem; }
.ligne__actions { display: flex; gap: 8px; flex: 0 0 auto; }

.tableau { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.tableau th {
  text-align: left; color: var(--muted); font-weight: 700;
  font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.05em;
  padding: 10px 8px; border-bottom: 1px solid var(--line);
}
.tableau td { padding: 12px 8px; border-bottom: 1px solid var(--line); }
.tableau tbody tr:hover { background: #f9fbff; }

/* ------------------------------------------------------------- boutons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--cible); min-width: var(--cible);
  padding: 0 16px;
  border-radius: var(--rayon-pill);
  border: 1px solid transparent;
  font-weight: 700; font-size: 0.88rem;
  cursor: pointer;
  background: var(--card); color: var(--ink);
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}
.btn:hover { text-decoration: none; }
.btn--primaire { background: var(--blue); color: #fff; }
.btn--primaire:hover { background: var(--blue-sombre); }
.btn--danger { background: var(--red); color: #fff; }
.btn--fantome { background: transparent; border-color: var(--line); color: var(--ink); }
.btn--fantome:hover { background: #eef3fa; }
.btn--icone { padding: 0; width: var(--cible); }
.btn--large { width: 100%; }
.btn[disabled] { opacity: 0.5; cursor: not-allowed; }

/* ------------------------------------------------------- formulaires ------ */
.champ { display: flex; flex-direction: column; gap: 6px; }
.champ + .champ { margin-top: 14px; }
.champ label { font-size: 0.82rem; font-weight: 700; }
.champ input,
.champ select,
.champ textarea {
  min-height: var(--cible);
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--rayon-sm);
  background: var(--card);
  color: var(--ink);
  font: inherit;
  width: 100%;
}
.champ__erreur { color: #ad1f3c; font-size: 0.8rem; font-weight: 600; }
.champ__aide { color: var(--muted); font-size: 0.78rem; }

/* --------------------------------------------------------- état vide ------ */
.etat-vide {
  display: flex; flex-direction: column; align-items: center; text-align: center;
  gap: 10px; padding: 44px 20px;
  color: var(--muted);
}
.etat-vide__icone {
  width: 56px; height: 56px; border-radius: 50%;
  background: #eef3fa; color: var(--blue);
  display: grid; place-items: center;
}
.etat-vide__titre { color: var(--ink); font-size: 1rem; font-weight: 800; }
.etat-vide__texte { max-width: 46ch; }

/* ----------------------------------------------------------- toasts ------- */
.toasts {
  position: fixed; right: 20px; bottom: 20px; z-index: 60;
  display: flex; flex-direction: column; gap: 10px;
  max-width: min(380px, calc(100vw - 40px));
}
.toast {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 14px;
  border-radius: var(--rayon-sm);
  background: var(--card);
  border: 1px solid var(--line);
  border-left: 4px solid var(--blue);
  box-shadow: var(--ombre-forte);
  font-size: 0.88rem;
}
.toast--succes { border-left-color: var(--green); }
.toast--erreur { border-left-color: var(--red); }
.toast--alerte { border-left-color: var(--amber); }
.toast__fermer {
  background: none; border: 0; cursor: pointer; color: var(--muted);
  font-size: 1.1rem; line-height: 1; padding: 4px;
}

/* -------------------------------------------------------- pagination ------ */
.pagination { display: flex; align-items: center; gap: 8px; justify-content: center; padding-top: 14px; }
.pagination__info { color: var(--muted); font-size: 0.82rem; }

/* --------------------------------------------------------- connexion ------ */
.connexion {
  min-height: 100vh;
  display: grid; place-items: center;
  padding: 24px;
  background: radial-gradient(120% 100% at 0% 0%, #1d2547 0%, var(--navy) 60%);
}
.connexion__carte {
  width: min(420px, 100%);
  background: var(--card);
  border-radius: var(--rayon);
  box-shadow: var(--ombre-forte);
  padding: 28px;
}
.connexion__marque { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }

/* ------------------------------------------------------- bandeau offline -- */
.bandeau-offline {
  display: none;
  background: var(--amber); color: #2b1c02;
  padding: 10px 16px; font-weight: 700; font-size: 0.85rem; text-align: center;
}
body.hors-ligne .bandeau-offline { display: block; }

/* ------------------------------------------------------------ responsive -- */
.nav-mobile { display: none; }
.burger { display: none; }

@media (max-width: 900px) {
  .sidebar {
    transform: translateX(-100%);
    transition: transform var(--transition);
    box-shadow: var(--ombre-forte);
    width: 260px;
  }
  .sidebar.est-ouverte { transform: translateX(0); }
  .contenu { margin-left: 0; padding-bottom: 72px; }
  .burger { display: inline-flex; }
  .page { padding: 16px; }

  /* Topbar sur 2 rangées : (burger + titre + action) puis la recherche. */
  .topbar { flex-wrap: wrap; row-gap: 10px; padding: 12px 16px; }
  .topbar__titres { flex: 1 1 30%; }
  .topbar__titres h1 {
    font-size: 1.1rem;
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  .topbar__sous-titre { display: none; }
  .topbar__actions { flex: 0 0 auto; }
  .recherche { order: 3; flex: 1 1 100%; }
  .recherche input { width: 100%; max-width: none; }

  /* Bouton primaire en icône seule — le libellé reste lu par les lecteurs d'écran. */
  .topbar__actions .btn--primaire { padding: 0; width: var(--cible); }
  .topbar__actions .btn--primaire span {
    position: absolute; width: 1px; height: 1px;
    padding: 0; margin: -1px; overflow: hidden;
    clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }

  .nav-mobile {
    display: flex;
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
    background: var(--navy);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    padding: 6px 4px;
  }
  .nav-mobile__item {
    flex: 1;
    min-height: var(--cible);
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 2px;
    color: #c3cbe2; font-size: 0.66rem; font-weight: 700;
    border-radius: var(--rayon-sm);
    position: relative;
  }
  .nav-mobile__item[aria-current="page"] { color: #fff; background: rgba(255,255,255,0.1); }
  .nav-mobile__item:hover { text-decoration: none; }
  .nav-mobile .badge-compteur { position: absolute; top: 2px; right: 22%; }

  .voile {
    position: fixed; inset: 0; z-index: 35;
    background: rgba(20, 24, 46, 0.45);
  }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}

@media print {
  .sidebar, .topbar__actions, .nav-mobile, .toasts { display: none !important; }
  .contenu { margin-left: 0; }
}

/* --------------------------------------------------- pages d'erreur ------- */
.page-erreur { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: var(--bg); }
.page-erreur__carte { max-width: 460px; text-align: center; padding: 40px 32px; }
.page-erreur__code { font-size: 56px; font-weight: 800; color: var(--blue); margin: 0; line-height: 1; }
.page-erreur__titre { font-size: 22px; margin: 12px 0 8px; color: var(--ink); }
.page-erreur__message { color: var(--muted); margin: 0 0 24px; }
.page-erreur__actions { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }

/* ------------------------------------------------ groupes non rattachés --- */
.liste-groupes { display: grid; gap: 12px; }
.carte--groupe { padding: 14px 16px; }
.groupe__sujet { margin: 0 0 2px; font-size: 15px; }
.groupe__dernier { color: var(--muted); font-style: italic; margin: 8px 0; }
.groupe__actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 8px; }
.groupe__actions form { margin: 0; }
.groupe__rattacher { display: flex; gap: 8px; align-items: center; flex-basis: 100%; margin-top: 6px; }
.groupe__rattacher select { min-width: 240px; }
.btn--petit { padding: 6px 12px; font-size: 13px; }
