:root {
  --bleu:    #1A3C5E;
  --orange:  #F7941D;
  --gris-bg: #F4F6F9;
  --sidebar-w: 260px;
}

body { background: var(--gris-bg); font-family: 'Segoe UI', sans-serif; font-size: 0.9rem; overflow: hidden; }

/* LAYOUT GLOBAL sticky */
#wrapper { height: 100vh; overflow: hidden; }
#page-content { display: flex; flex-direction: column; flex: 1; overflow: hidden; }
.main-content { flex: 1; overflow-y: auto; padding: 1.5rem; }

/* SIDEBAR */
#sidebar {
  width: var(--sidebar-w);
  height: 100vh;
  position: sticky;
  top: 0;
  background: var(--bleu);
  color: #fff;
  transition: width .25s;
  flex-shrink: 0;
  overflow-y: auto;
  overflow-x: hidden;
}
#sidebar.collapsed { width: 60px; }
#sidebar.collapsed .sidebar-brand span,
#sidebar.collapsed .nav-section,
#sidebar.collapsed .nav-link span,
#sidebar.collapsed .user-info span,
#sidebar.collapsed .user-info .badge { display: none; }
#sidebar.collapsed .nav-link { justify-content: center; padding: .6rem; }

.sidebar-brand {
  padding: 1.2rem 1rem;
  font-size: 1.1rem;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.1);
  display: flex;
  align-items: center;
  gap: .6rem;
}
.text-orange { color: var(--orange) !important; }

.exercice-badge {
  background: rgba(247,148,29,.15);
  border-left: 3px solid var(--orange);
  padding: .5rem 1rem;
  font-size: .78rem;
  margin: .5rem;
  border-radius: 4px;
}

.nav-section {
  font-size: .65rem;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: rgba(255,255,255,.4);
  padding: .8rem 1rem .2rem;
  font-weight: 600;
}

#sidebar .nav-link {
  color: rgba(255,255,255,.75);
  padding: .5rem 1rem;
  border-radius: 6px;
  margin: .1rem .5rem;
  display: flex;
  align-items: center;
  gap: .6rem;
  transition: all .2s;
}
#sidebar .nav-link:hover,
#sidebar .nav-link.active {
  background: rgba(247,148,29,.2);
  color: #fff;
}
#sidebar .nav-link.active { border-left: 3px solid var(--orange); }
#sidebar .nav-link i { font-size: 1rem; min-width: 18px; }

.sidebar-footer {
  padding: 1rem;
  border-top: 1px solid rgba(255,255,255,.1);
  font-size: .8rem;
}

/* TOP BAR */
.top-bar {
  background: #fff;
  border-bottom: 1px solid #e0e6ed;
  min-height: 50px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

/* CARDS */
.card { border: none; border-radius: 10px; box-shadow: 0 2px 12px rgba(0,0,0,.06); }
.card-header { border-bottom: 1px solid #f0f0f0; background: #fff; border-radius: 10px 10px 0 0 !important; font-weight: 600; }

/* KPI CARDS */
.kpi-card { border-left: 4px solid var(--orange); }
.kpi-card .kpi-value { font-size: 1.6rem; font-weight: 700; color: var(--bleu); }
.kpi-card .kpi-label { font-size: .78rem; color: #6c757d; text-transform: uppercase; letter-spacing: .05em; }
.kpi-card .kpi-icon { font-size: 2rem; opacity: .15; }

/* TABLES */
.table thead th { background: var(--bleu); color: #fff; font-size: .8rem; font-weight: 600; border: none; }
.table-hover tbody tr:hover { background: rgba(26,60,94,.04); }
.table td { vertical-align: middle; font-size: .87rem; }

/* BADGES */
.badge { font-size: .75rem; }
.badge-statut-EMISE            { background:#0d6efd !important; }
.badge-statut-SOLDEE           { background:#198754 !important; }
.badge-statut-PARTIELLEMENT_PAYEE { background:#fd7e14 !important; }
.badge-statut-ANNULEE          { background:#dc3545 !important; }
.badge-statut-BROUILLON        { background:#6c757d !important; }

/* BUTTONS */
.btn-primary { background: var(--bleu); border-color: var(--bleu); }
.btn-primary:hover { background: #12294a; border-color: #12294a; }
.btn-orange { background: var(--orange); border-color: var(--orange); color: #fff; }
.btn-orange:hover { background: #e07d0d; color: #fff; }
.btn-outline-orange { color: var(--orange); border-color: var(--orange); }
.btn-outline-orange:hover { background: var(--orange); color: #fff; }

/* FORMS */
.form-label { font-weight: 500; font-size: .85rem; }
.form-control:focus, .form-select:focus { border-color: var(--orange); box-shadow: 0 0 0 .2rem rgba(247,148,29,.2); }

/* MONTANTS */
.montant { font-family: 'Courier New', monospace; font-weight: 600; text-align: right; white-space: nowrap; }
.montant-credit { color: #198754; }
.montant-debit  { color: #dc3545; }

/* ALERT IMPAYÉ */
.impaye-alert { background: #fff3cd; border-left: 4px solid #ffc107; }

/* Exercice dans la top-bar */
.topbar-exo {
    display: flex;
    align-items: center;
    gap: .4rem;
    padding: .3rem .75rem;
    background: rgba(247,148,29,.1);
    border: 1px solid rgba(247,148,29,.35);
    border-radius: 20px;
    font-size: .82rem;
    font-weight: 600;
    color: #1A3C5E;
    white-space: nowrap;
    transition: background .2s, border-color .2s;
}
.topbar-exo:hover {
    background: rgba(247,148,29,.2);
    border-color: #F7941D;
}
.topbar-exo-libelle {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.topbar-exo-changer {
    color: #F7941D;
    font-size: .8rem;
    margin-left: .1rem;
}
.text-orange { color: #F7941D !important; }

/* ============================================================
   RESPONSIVE — sidebar en tiroir (off-canvas) sur mobile
   ============================================================ */
#sidebar-backdrop { display: none; }

@media (max-width: 768px) {
  /* La sidebar devient un tiroir superposé, masqué par défaut */
  #sidebar {
    position: fixed;
    left: 0; top: 0;
    width: 250px;
    z-index: 1050;
    transform: translateX(-100%);
    transition: transform .25s ease;
    box-shadow: 2px 0 16px rgba(0,0,0,.35);
  }
  body.sidebar-mobile-open #sidebar { transform: translateX(0); }
  /* Annuler le mode "rétréci" desktop sur mobile */
  #sidebar.collapsed { width: 250px; }
  #sidebar.collapsed .sidebar-brand span,
  #sidebar.collapsed .nav-section,
  #sidebar.collapsed .nav-link span,
  #sidebar.collapsed .user-info span,
  #sidebar.collapsed .user-info .badge { display: inline; }

  /* Voile sombre quand le tiroir est ouvert */
  #sidebar-backdrop {
    position: fixed; inset: 0;
    background: rgba(0,0,0,.45);
    z-index: 1040;
  }
  body.sidebar-mobile-open #sidebar-backdrop { display: block; }

  /* Contenu : pleine largeur, padding réduit */
  .main-content { padding: .75rem; }
  .top-bar { flex-wrap: wrap; gap: .35rem; padding-left: .75rem !important; padding-right: .75rem !important; }
  .top-bar nav[aria-label="breadcrumb"] { display: none; }   /* gagne de la place */
  .topbar-exo { padding: .25rem .55rem; font-size: .75rem; }
  .topbar-exo-libelle { max-width: 90px; }

  /* Tableaux : défilement horizontal dans les cartes */
  .card-body.p-0 { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table { font-size: .82rem; }

  /* Titres un peu plus compacts */
  h5 { font-size: 1.05rem; }
}

@media (max-width: 480px) {
  .top-bar .text-muted.small { display: none; }   /* la date */
  .main-content { padding: .5rem; }
}
