:root {
  --bf-sidebar-w: 250px;
  --bf-sidebar-bg: #ffffff;
  --bf-brand: #0d6efd;
}

body {
  background-color: #f4f6f9;
  font-size: .925rem;
}

/* ---------- Layout applicatif ---------- */
.app-wrapper { min-height: 100vh; }

.app-sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--bf-sidebar-w);
  background: var(--bf-sidebar-bg);
  border-right: 1px solid #e5e8ec;
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .55rem;
  font-size: 1.05rem;
  padding: 1rem 1.1rem;
  border-bottom: 1px solid #eef0f3;
  color: #212529;
}
.sidebar-brand i { color: var(--bf-brand); font-size: 1.35rem; }
.sidebar-brand .sidebar-logo { height: 32px; width: auto; max-width: 100%; object-fit: contain; }
.sidebar-brand b { color: #ffc107; }

.sidebar-nav { padding: .75rem .6rem; overflow-y: auto; }
.sidebar-nav .nav-section {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: #8a94a6;
  margin: .9rem .55rem .25rem;
}
.sidebar-link {
  display: flex;
  align-items: center;
  gap: .65rem;
  color: #3d4757;
  text-decoration: none;
  padding: .52rem .7rem;
  border-radius: .45rem;
  margin-bottom: .12rem;
}
.sidebar-link i { width: 1.15rem; text-align: center; }
.sidebar-link:hover { background: #eef3ff; color: var(--bf-brand); }
.sidebar-link.active { background: var(--bf-brand); color: #fff; }
.sidebar-link .count-badge {
  margin-left: auto;
  background: #dc3545;
  color: #fff;
  border-radius: 999px;
  font-size: .66rem;
  padding: .08rem .42rem;
}

.sidebar-foot {
  margin-top: auto;
  padding: .8rem 1.1rem;
  font-size: .72rem;
  color: #98a2b3;
  border-top: 1px solid #eef0f3;
}

/* Variante admin (sombre) */
.sidebar-admin { background: #1c2333; }
.sidebar-admin .sidebar-brand { color: #fff; border-color: rgba(255,255,255,.07); }
.sidebar-admin .sidebar-brand i { color: #ffc107; }
.sidebar-admin .sidebar-link { color: #b8c1d1; }
.sidebar-admin .sidebar-link:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar-admin .sidebar-link.active { background: #ffc107; color: #212529; }
.sidebar-admin .sidebar-foot { color: #77839a; border-color: rgba(255,255,255,.07); }

/* Bloc organisation connectée (sidebar) */
.sidebar-org {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: .8rem 1.1rem;
  border-bottom: 1px solid #eef0f3;
  background: #f8fafc;
}
.org-avatar {
  width: 36px;
  height: 36px;
  border-radius: .55rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: linear-gradient(135deg, #0d6efd, #0a58ca);
  color: #fff;
  font-weight: 700;
  font-size: .95rem;
  flex-shrink: 0;
}
.org-meta { min-width: 0; line-height: 1.25; }
.org-meta strong {
  display: block;
  font-size: .84rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.org-meta small {
  display: block;
  color: #8a94a6;
  font-size: .7rem;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.sidebar-admin .sidebar-org { background: rgba(255,255,255,.03); border-color: rgba(255,255,255,.07); }
.sidebar-admin .org-avatar { background: #ffc107; color: #212529; }
.sidebar-admin .org-meta strong { color: #fff; }
.sidebar-admin .org-meta small { color: #77839a; }

.app-main { margin-left: var(--bf-sidebar-w); min-height: 100vh; display: flex; flex-direction: column; }

.app-topbar {
  position: sticky;
  top: 0;
  z-index: 1020;
  display: flex;
  align-items: center;
  gap: .5rem;
  padding: .55rem 1.25rem;
  background: #fff;
  border-bottom: 1px solid #e5e8ec;
}

.topbar-search {
  position: relative;
  display: flex;
  align-items: center;
  gap: .5rem;
  background: #f1f3f6;
  border-radius: 999px;
  padding: .32rem .9rem;
  max-width: 430px;
  width: 100%;
}
.topbar-search input {
  border: 0;
  outline: none;
  background: transparent;
  width: 100%;
  font-size: 1rem;
}
.search-results {
  position: absolute;
  top: calc(100% + .4rem);
  left: 0;
  right: 0;
  z-index: 1050;
  box-shadow: 0 .5rem 1rem rgba(16,24,40,.14);
  max-height: 330px;
  overflow-y: auto;
}
.search-results .search-type {
  font-size: .68rem;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: #8a94a6;
}

.topbar-actions { display: flex; align-items: center; gap: .35rem; }

.notify-dot {
  position: absolute;
  top: -2px;
  right: -4px;
  background: #dc3545;
  color: #fff;
  font-size: .62rem;
  line-height: 1;
  border-radius: 999px;
  padding: .18rem .34rem;
  min-width: 17px;
}
.notify-menu { min-width: 280px; max-height: 380px; overflow-y: auto; }

.user-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bf-brand);
  color: #fff;
  font-weight: 600;
  font-size: .82rem;
  flex-shrink: 0;
}
.user-avatar-lg { width: 46px; height: 46px; font-size: 1.15rem; }

.app-content { padding: 1.4rem 1.5rem 2.5rem; flex-grow: 1; }

/* Conteneur de graphique : hauteur bornee, obligatoire avec Chart.js.
   Sans hauteur fixe, maintainAspectRatio:false mesure un parent qui grandit
   a chaque resize, ce qui fait boucler la hauteur de la page. */
.chart-box { position: relative; width: 100%; }
.chart-box-sm { height: 180px; }
.chart-box-md { height: 220px; }
.chart-box-lg { height: 300px; }
.chart-box canvas { display: block; }

/* Guide utilisateur : sommaire collant + ancres passees sous la barre superieure */
.guide-toc {
  position: sticky;
  top: 64px;
  max-height: calc(100vh - 84px);
  overflow-y: auto;
}
.guide-section { scroll-margin-top: 72px; }
.guide-body h4, .guide-body h5 { margin-top: 1.15rem; }
.guide-body p { margin-bottom: .7rem; }
.guide-body ul, .guide-body ol { padding-left: 1.2rem; margin-bottom: .8rem; }
.guide-body li { margin-bottom: .25rem; }
.guide-body blockquote { margin-bottom: .8rem; }
.guide-body code { white-space: normal; word-break: break-word; }
@media (max-width: 991.98px) {
  .guide-toc { position: static; max-height: none; overflow-y: visible; }
  .guide-section { scroll-margin-top: 72px; }
}

.app-footer {
  padding: .7rem 1.25rem;
  font-size: .74rem;
  color: #98a2b3;
  border-top: 1px solid #e8ebef;
  background: #fff;
}

.backdrop,
.sidebar-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 36, .45);
  z-index: 1035;
  opacity: 0;
  pointer-events: none;
  transition: opacity .25s ease;
}

@media (max-width: 991.98px) {
  .app-sidebar { transform: translateX(-100%); box-shadow: 0 0 2rem rgba(0,0,0,.15); }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .app-main { margin-left: 0; }
  .topbar-search { max-width: none; }
}

/* ---------- Cartes statistiques ---------- */
.stat-card {
  background: #fff;
  border: 1px solid #e8ebef;
  border-radius: .65rem;
  padding: .95rem 1.1rem;
  display: flex;
  align-items: center;
  gap: .95rem;
  height: 100%;
  box-shadow: 0 1px 2px rgba(16,24,40,.04);
}
.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: .6rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.stat-label { font-size: .76rem; color: #8a94a6; text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.32rem; font-weight: 700; line-height: 1.15; }
.stat-sub { font-size: .74rem; color: #8a94a6; }

/* ---------- Pages auth ---------- */
.auth-body {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background:
    radial-gradient(1100px 500px at 10% -10%, rgba(13,110,253,.18), transparent 60%),
    radial-gradient(900px 500px at 110% 110%, rgba(25,135,84,.14), transparent 55%),
    #101828;
}
.auth-card {
  width: 100%;
  max-width: 430px;
  border-radius: 1rem;
  overflow: hidden;
  border: 0;
}
.auth-head {
  background: linear-gradient(135deg, #0d6efd, #0a58ca);
  color: #fff;
  padding: 1.6rem 1.5rem 1.3rem;
}
.auth-head .logo { font-size: 2.1rem; }
.brand-name { letter-spacing: .02em; }
.auth-body-inner { padding: 1.5rem; }

.plan-ribbon {
  position: absolute;
  top: 14px;
  right: -38px;
  transform: rotate(38deg);
  background: #ffc107;
  color: #212529;
  font-size: .68rem;
  font-weight: 700;
  padding: .18rem 2.6rem;
  letter-spacing: .06em;
  text-transform: uppercase;
}
.position-relative { position: relative !important; }

/* ---------- Tables & divers ---------- */
.table > :not(caption) > * > * { padding: .55rem .6rem; }
.table td, .table th { vertical-align: middle; }
.card-header { font-size: .92rem; }

.pagination { margin-bottom: 0; }

[data-bs-theme="dark"] { color-scheme: dark; }

/* ---------- Mode support (impersonation admin plateforme) ---------- */
.impersonation-bar {
  background: #ffc107;
  color: #212529;
  border-bottom: 1px solid #e0a800;
  position: sticky;
  top: 0;
  z-index: 1050;
  font-size: .875rem;
}

/* ---------- Landing page publique ---------- */
.lp-body { background: #fff; font-size: 1rem; }

.lp-navbar {
  background: #101828;
  min-height: 56px;
  padding-top: .2rem;
  padding-bottom: .2rem;
}
.lp-navbar .navbar-brand, .lp-navbar .nav-link { color: #e6e9ef; }
.lp-navbar .nav-link:hover, .lp-navbar .navbar-brand:hover { color: #fff; }
.lp-navbar .navbar-brand { font-size: 1rem; gap: .4rem !important; }
.lp-navbar .navbar-brand b, .lp-footer b { color: #ffc107; }
.lp-navbar .nav-link { font-size: .88rem; padding: .35rem .7rem; }
.lp-navbar .btn { font-size: .82rem; padding: .3rem .75rem; }
.lp-navbar .navbar-toggler { border: 1px solid rgba(255,255,255,.28); border-radius: .5rem; padding: .25rem .5rem; font-size: 1.1rem; }
.lp-navbar .navbar-toggler:focus { box-shadow: none; }
.lp-navbar .navbar-toggler-icon { filter: invert(1) brightness(2); }
.lp-brand-icon { color: #4d94ff; }
.lp-brand-logo { height: 30px; width: auto; }
@media (max-width: 575.98px) {
  .lp-brand-logo { height: 24px; }
  .lp-navbar { min-height: 50px; }
  .lp-navbar .btn { font-size: .78rem; padding: .25rem .6rem; }
}

.lp-hero {
  background-image: linear-gradient(160deg, rgba(16,24,40,.85) 0%, rgba(27,42,74,.75) 100%),
                    url('../images/fond.png');
  background-size: cover;
  background-position: center;
  color: #fff;
}
.lp-hero-badge {
  background: rgba(77, 148, 255, .18);
  color: #9ec2ff;
  border: 1px solid rgba(77, 148, 255, .35);
  padding: .5em .9em;
}
.lp-hero-checks li { margin-bottom: .35rem; }
.lp-hero-card {
  background: #fff;
  color: #212529;
  border-radius: 1rem;
  padding: 1.4rem 1.5rem;
  max-width: 420px;
  margin-inline: auto;
}
.lp-hero-stat { font-size: 1.25rem; font-weight: 700; }

.lp-strip { background: #f4f6f9; border-bottom: 1px solid #eef0f3; }

.lp-feature-card { transition: transform .15s ease, box-shadow .15s ease; }
.lp-feature-card:hover { transform: translateY(-4px); box-shadow: 0 .75rem 1.5rem rgba(16, 24, 40, .08) !important; }
.lp-feature-icon {
  width: 46px; height: 46px;
  display: flex; align-items: center; justify-content: center;
  border-radius: .7rem;
  background: #e7f0ff;
  color: var(--bf-brand);
  font-size: 1.3rem;
}

.lp-step-num {
  width: 52px; height: 52px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 50%;
  background: var(--bf-brand);
  color: #fff;
  font-size: 1.3rem; font-weight: 700;
}

.lp-price-card { position: relative; }
.lp-price-popular .plan-ribbon { top: -1px; right: 14px; }
.plan-ribbon {
  position: absolute;
  background: var(--bf-brand);
  color: #fff;
  font-size: .68rem;
  letter-spacing: .06em;
  text-transform: uppercase;
  padding: .28em .85em;
  border-radius: 0 0 .45rem .45rem;
}

.lp-cta-band {
  background: linear-gradient(135deg, #101828 0%, #1b2a4a 60%, #0d6efd 130%);
  color: #fff;
}

.lp-footer { background: #101828; color: #cdd3dd; }
.lp-footer h6 { color: #8a94a6; }
.lp-footer a { color: #cdd3dd; text-decoration: none; }
.lp-footer a:hover { color: #fff; }

/* Pages legales (conditions & confidentialite) */
.lp-legal-body { color: #3d4756; line-height: 1.75; font-size: .97rem; }
.lp-legal-body h1, .lp-legal-body h2, .lp-legal-body h3, .lp-legal-body h4 {
  color: #101828; margin-top: 1.6rem; margin-bottom: .75rem; font-weight: 700;
}
.lp-legal-body h2 { font-size: 1.3rem; }
.lp-legal-body h3 { font-size: 1.12rem; }
.lp-legal-body h1 { font-size: 1.5rem; }
.lp-legal-body p { margin-bottom: 1rem; }
.lp-legal-body ul, .lp-legal-body ol { padding-left: 1.3rem; margin-bottom: 1rem; }
.lp-legal-body li { margin-bottom: .4rem; }
.lp-legal-body blockquote { border-left: 3px solid #0d6efd; padding-left: 1rem; color: #667085; margin: 1rem 0; }
.lp-legal-body a { color: #0d6efd; }
.lp-legal-body table { width: 100%; margin: 1rem 0; border-collapse: collapse; }
.lp-legal-body th, .lp-legal-body td { border: 1px solid #e4e7ec; padding: .5rem .75rem; text-align: left; }
.lp-legal-body code, .lp-legal-body pre { background: #f2f4f7; border-radius: .25rem; }
.lp-legal-body code { padding: .1em .35em; }
.lp-legal-body pre { padding: .75rem 1rem; overflow-x: auto; }

/* ---------- Responsive & multi-support (mobile / tablette / grand ecran) ---------- */
html { -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; scroll-padding-top: 80px; }
body { overflow-x: hidden; }

/* Confort tactile minimal sur tout l'app */
.btn, .form-control, .form-select, .dropdown-item, .sidebar-link, .input-group-text { border-radius: .45rem; }
.sidebar-link { min-height: 40px; }
.table .btn.btn-sm, .table .form-control, .table .form-select { min-height: 0; }

/* Tableaux : défilement horizontal fluide sur mobile */
.table-responsive { -webkit-overflow-scrolling: touch; scrollbar-width: thin; }
.table-responsive::-webkit-scrollbar { height: 8px; }
.table-responsive::-webkit-scrollbar-thumb { background: #c3cad6; border-radius: 999px; }
.table-responsive::-webkit-scrollbar-track { background: #eef0f3; }

/* Très petits écrans (portrait smartphones) */
@media (max-width: 575.98px) {
  .app-content { padding: 1rem 0.9rem 2rem; }
  .app-topbar { padding: .5rem .6rem; gap: .35rem; }
  .topbar-search { padding: .3rem .7rem; }
  .topbar-actions { gap: .1rem; }
  .topbar-actions .btn { padding: .25rem .4rem; }
  .app-footer { padding: .6rem .7rem; text-align: center; }
  .stat-value { font-size: 1.2rem; }
  .card-body { padding: 1rem .9rem; }
  .page-title { font-size: 1.25rem; }
  h1 { font-size: 1.55rem; }
  /* Empêcher l'overflow horizontal des cartes/grids */
  .row > .col-6 { padding-left: .5rem; padding-right: .5rem; }
  .auth-body { padding: 1rem; }
  .auth-header h2, .h5 { line-height: 1.3; }
  /* Landing page : héro et CTA adaptés aux petits écrans */
  .lp-hero h1.display-5 { font-size: 2.05rem; }
  .lp-hero-card { padding: 1.15rem 1.05rem; }
  .lp-cta-band { padding: 2.25rem 1.25rem !important; }
}

/* Téléphones & tablettes portrait */
@media (max-width: 767.98px) {
  /* Topbar sur 2 lignes : actions en haut, recherche pleine largeur en dessous */
  .app-topbar { flex-wrap: wrap; row-gap: .5rem; }
  .app-topbar > [data-sidebar-toggle] { order: 1; }
  .app-topbar .topbar-actions { order: 2; margin-left: auto; }
  .app-topbar .topbar-search { order: 3; flex-basis: 100%; max-width: none; padding: .45rem .8rem; }

  /* Zones tactiles confortables pour les actions du haut */
  .topbar-actions .btn { min-width: 38px; min-height: 38px; }

  /* Champs à 16px minimum : évite le zoom automatique de Safari iOS au focus */
  input[type="text"], input[type="search"], input[type="email"], input[type="password"],
  input[type="tel"], input[type="number"], input[type="date"], input[type="datetime-local"],
  select, textarea { font-size: 16px; }

  .card-header { flex-wrap: wrap; gap: .35rem; }
  .dropdown-menu { max-width: calc(100vw - 1.5rem); }
  .notify-menu { min-width: 0; right: 0; width: calc(100vw - 2.5rem); }
  .stat-card { padding: .8rem .9rem; gap: .8rem; }
  .btn-group > .btn, .d-flex.gap-2 .btn { font-size: .85rem; }
}

/* Tablettes paysage / petits écrans de bureau (< lg) — géré plus haut dans la section layout */

/* Grand écrans de bureau */
@media (min-width: 1400px) {
  .app-content { padding: 1.8rem 2rem 3rem; }
  .content-container { max-width: 1400px; margin-inline: auto; }
  body { font-size: .95rem; }
}

/* Très grands écrans : centrer le contenu pour ne pas étirer cartes et tableaux */
@media (min-width: 1600px) {
  .app-content > * { max-width: 1540px; margin-inline: auto; }
}

/* Support encoches iPhone / Android (barre supérieure et sidebar) */
@supports (padding: max(0px, env(safe-area-inset-top))) {
  .app-topbar { top: max(0px, env(safe-area-inset-top)); }
  .app-sidebar { padding-bottom: max(0px, env(safe-area-inset-bottom)); }
  .auth-body { padding-top: max(1.5rem, env(safe-area-inset-top)); padding-bottom: max(1.5rem, env(safe-area-inset-bottom)); }
}
@media print {
  .app-sidebar, .app-topbar, .app-footer, .btn, form.d-print-none,
  .alert-dismissible .btn-close, .no-print { display: none !important; }
  .app-main { margin-left: 0 !important; }
  .app-content { padding: 0 !important; }
  body { background: #fff; }
  .card { border: 1px solid #ccc !important; box-shadow: none !important; break-inside: avoid; }
  a { text-decoration: none !important; color: inherit; }
}

/* ---------- Theme noir & blanc ---------- */
body.bw-mode * {
  filter: grayscale(1) !important;
}
body.bw-mode { background-color: #fff; }
body.bw-mode .app-sidebar { background-color: #212529; }
body.bw-mode .sidebar-brand,
body.bw-mode .sidebar-link,
body.bw-mode .sidebar-org,
body.bw-mode .sidebar-foot { color: #fff; }
body.bw-mode .sidebar-link:hover { background: rgba(255,255,255,.08); color: #fff; }
