/* =============================================
   ALLIANCE DISTRIBUTION — CSS Custom v3
   Palette logos : Marine #1B3A6B | Orange #E8760A
   ============================================= */

:root {
  --navy:        #1B3A6B;
  --navy-dark:   #112650;
  --navy-lt:     #254e8f;
  --navy-xlt:    #EBF0F8;

  --orange:      #E8760A;
  --orange-dark: #C45F05;
  --orange-lt:   #FFF3E0;
  --orange-mid:  #FAD4A0;

  /* Alias pour compatibilité templates */
  --red:         #E8760A;
  --red-dark:    #C45F05;
  --red-light:   #FFF3E0;

  /* Neutres */
  --bg:          #F0F3F8;
  --surface:     #FFFFFF;
  --border:      #DDE4EF;
  --text:        #1B2B40;
  --text-muted:  #6B7A99;

  --sidebar-w:   252px;

  /* Typographie harmonisée */
  --fs-xs:    11px;
  --fs-sm:    12px;
  --fs-base:  14px;
  --fs-md:    15px;
  --fs-lg:    17px;
  --fs-xl:    20px;
  --fs-2xl:   24px;
  --fs-3xl:   28px;
}

/* ===== RESET / BASE ===== */
*, *::before, *::after { box-sizing: border-box; }

html { font-size: 14px; }

body {
  font-family: 'Nunito', sans-serif;
  font-size: var(--fs-base);
  line-height: 1.55;
  background: var(--bg);
  color: var(--text);
  overflow-x: hidden;   /* ← empêche le débordement horizontal */
}

h1, h2, h3, h4, h5, h6,
.card-title, .stat-value, .ref-cell {
  font-family: 'Oswald', sans-serif;
}

/* ===== SIDEBAR ===== */
.sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: linear-gradient(180deg, var(--navy-dark) 0%, var(--navy) 100%);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  box-shadow: 4px 0 32px rgba(17,38,80,0.35);
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar::before {
  content: '';
  display: block;
  height: 3px;
  background: linear-gradient(90deg, var(--orange), #f7b733);
  flex-shrink: 0;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  flex-shrink: 0;
}
.sidebar-logo img {
  max-width: calc(var(--sidebar-w)/2 - 20px);
  object-fit: contain;
}

/* Classes héritées conservées */
.logo-icon {
  width: 40px; height: 40px;
  background: var(--orange);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Oswald', sans-serif;
  font-size: 16px; font-weight: 900;
  color: #fff; flex-shrink: 0;
}
.logo-main { display: block; font-family: 'Oswald', sans-serif; font-size: 13px; font-weight: 700; color: #fff; }
.logo-sub  { display: block; font-size: 10px; color: rgba(255,255,255,0.4); }

/* ── Nav ── */
.sidebar-nav { flex: 1; padding: 14px 10px; }

.nav-section-label {
  display: block;
  font-size: var(--fs-xs);
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 1.5px;
  color: rgba(255,255,255,0.28);
  padding: 0 12px 5px;
}
.nav-link-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 13px;
  border-radius: 8px;
  color: rgba(255,255,255,0.58);
  text-decoration: none;
  font-size: var(--fs-base);
  font-weight: 600;
  margin-bottom: 2px;
  transition: all 0.18s ease;
  border-left: 3px solid transparent;
  white-space: nowrap;
  overflow: hidden;
}
.nav-link-item i { font-size: 15px; width: 17px; flex-shrink: 0; }
.nav-link-item:hover {
  background: rgba(255,255,255,0.09);
  color: #fff;
  border-left-color: rgba(232,118,10,0.5);
}
.nav-link-item.active {
  background: linear-gradient(90deg, rgba(232,118,10,0.22), rgba(232,118,10,0.06));
  color: #fff; font-weight: 700;
  border-left-color: var(--orange);
}
.nav-link-item.active i { color: var(--orange); }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: var(--fs-xs);
  color: rgba(255,255,255,0.3);
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 1px;
  flex-shrink: 0;
}

/* ===== MAIN CONTENT ===== */
.main-content {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  width: calc(100% - var(--sidebar-w));  /* ← largeur stricte */
  overflow-x: hidden;                     /* ← pas de scroll horizontal */
}

/* ===== TOPBAR ===== */
.topbar {
  background: var(--navy);
  padding: 12px 24px;
  border-bottom: 3px solid var(--orange);
  position: sticky; top: 0; z-index: 1030;
  box-shadow: 0 2px 16px rgba(17,38,80,0.18);
  display: flex;
  align-items: center;
  width: 100%;           /* ← ne dépasse pas */
  overflow: hidden;
}
.topbar-title {
  font-family: 'Oswald', sans-serif;
  font-size: var(--fs-xl);
  font-weight: 700;
  color: #fff;
  letter-spacing: 0.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.sidebar-toggle { background: transparent; border: none; color: #fff; cursor: pointer; flex-shrink: 0; }
.date-badge {
  background: rgba(255,255,255,0.1);
  color: rgba(255,255,255,0.75);
  padding: 4px 12px;
  border-radius: 20px;
  font-size: var(--fs-sm);
  white-space: nowrap;
  flex-shrink: 0;
}
/* badges topbar flex-shrink pour ne pas déborder */
.topbar .badge { flex-shrink: 0; font-size: var(--fs-xs); }

/* ===== PAGE CONTENT ===== */
.page-content {
  padding: 22px 24px;
  flex: 1;
  min-width: 0;
}

/* ===== STAT CARDS ===== */
.stat-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 18px 20px;
  box-shadow: 0 2px 12px rgba(27,58,107,0.08);
  display: flex;
  align-items: center;
  gap: 14px;
  height: 100%;
  transition: box-shadow 0.2s, transform 0.2s;
}
.stat-card:hover {
  box-shadow: 0 6px 24px rgba(27,58,107,0.15);
  transform: translateY(-2px);
}
.stat-icon { font-size: 26px; flex-shrink: 0; }
.stat-label {
  font-size: var(--fs-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.stat-value {
  font-family: 'Oswald', sans-serif;
  font-size: var(--fs-3xl);
  font-weight: 700;
  color: var(--navy);
  line-height: 1.1;
}
.stat-sub { font-size: var(--fs-sm); color: var(--text-muted); margin-top: 2px; }

/* Couleurs bordures stat cards */
.border-danger  { border-color: var(--orange) !important; }
.text-danger    { color: var(--orange) !important; }

/* ===== CARDS ===== */
.card {
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 1px 8px rgba(27,58,107,0.07);
}
.card-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 13px 18px;
}
.card-title {
  font-family: 'Oswald', sans-serif;
  font-size: var(--fs-lg);
  font-weight: 700;
  color: var(--navy);
}
.card-body { padding: 18px; }

/* ===== TABLES ===== */
.table-dark { --bs-table-bg: var(--navy); }
.table > :not(caption) > * > * {
  padding: 10px 13px;
  vertical-align: middle;
  font-size: var(--fs-base);
}
.table thead th {
  font-family: 'Oswald', sans-serif;
  font-size: var(--fs-sm);
  font-weight: 700;
  letter-spacing: 0.4px;
  text-transform: uppercase;
}
.table-hover > tbody > tr:hover > * { background-color: var(--navy-xlt); }

/* ===== BADGES ===== */
.badge {
  font-family: 'Nunito', sans-serif;
  font-size: var(--fs-xs);
  font-weight: 700;
  padding: 4px 8px;
}

/* ===== BOUTONS ===== */
.btn-danger {
  background-color: var(--orange); border-color: var(--orange); color: #fff;
}
.btn-danger:hover, .btn-danger:focus {
  background-color: var(--orange-dark); border-color: var(--orange-dark); color: #fff;
}
.btn-outline-danger { color: var(--orange); border-color: var(--orange); }
.btn-outline-danger:hover { background-color: var(--orange); border-color: var(--orange); color: #fff; }
.btn {
  font-family: 'Nunito', sans-serif;
  font-weight: 700;
  border-radius: 8px;
  font-size: var(--fs-base);
}
.btn-sm { border-radius: 6px; font-size: var(--fs-sm); }
.btn-lg { font-size: var(--fs-md); }

/* ===== FORMULAIRES ===== */
.form-control, .form-select {
  border-color: var(--border);
  border-radius: 8px;
  font-family: 'Nunito', sans-serif;
  font-size: var(--fs-base);
}
.form-control:focus, .form-select:focus {
  border-color: var(--orange);
  box-shadow: 0 0 0 0.2rem rgba(232,118,10,0.18);
}
.form-check-input:checked { background-color: var(--orange); border-color: var(--orange); }
.form-label {
  font-family: 'Nunito', sans-serif;
  font-weight: 600;
  font-size: var(--fs-base);
}
.input-group-text {
  font-family: 'Nunito', sans-serif;
  font-size: var(--fs-base);
  background: var(--navy-xlt);
  border-color: var(--border);
  color: var(--navy);
}

/* ===== PROGRESS ===== */
.progress { background-color: var(--navy-xlt); border-radius: 8px; }
.progress-bar.bg-danger  { background-color: var(--orange) !important; }

/* ===== ALERTS ===== */
.alert-warning { background: var(--orange-lt); border-color: var(--orange-mid); color: #7a4500; }

/* ===== BADGES PRODUITS ===== */
.badge-produit {
  display: inline-block;
  background: var(--orange-lt); color: var(--orange-dark);
  border: 1px solid var(--orange-mid);
  padding: 3px 10px; border-radius: 6px;
  font-size: var(--fs-sm); font-weight: 700;
  white-space: nowrap; font-family: 'Nunito', sans-serif;
}
.badge-produit.orange {
  background: var(--navy-xlt); color: var(--navy); border-color: var(--border);
}
.badge-produit.big { font-size: var(--fs-base); padding: 5px 14px; }

/* ===== REF CELL ===== */
.ref-cell {
  font-family: 'Oswald', sans-serif;
  color: var(--navy); font-weight: 700;
  font-size: var(--fs-sm); white-space: nowrap;
}

/* ===== AMOUNT ===== */
.amount { font-weight: 800; color: var(--navy); white-space: nowrap; }

/* ===== STATUT SELECT ===== */
.statut-select {
  border: none; font-family: 'Nunito', sans-serif;
  font-size: var(--fs-xs); font-weight: 700;
  text-transform: uppercase; cursor: pointer;
  padding: 4px 8px; border-radius: 20px; min-width: 96px;
}
.statut-en_attente { background: #FFF3CD; color: #7a4500; }
.statut-paye_non_livre      { background: #D1ECF1; color: #0c5460; }
.statut-paye_et_livre      { background: #D4F5E4; color: #155724; }

/* ===== ENTITY AVATAR ===== */
.entity-avatar {
  width: 40px; height: 40px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-family: 'Oswald', sans-serif;
  font-size: 16px; font-weight: 700; flex-shrink: 0;
}

/* ===== PRICE PREVIEW BOX ===== */
.price-preview-box {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-lt) 100%);
  border-radius: 12px; padding: 18px;
  color: rgba(255,255,255,0.75);
}
.price-preview-label { font-size: var(--fs-xs); text-transform: uppercase; font-weight: 700; letter-spacing: 0.5px; margin-bottom: 5px; }
.price-preview-val { font-family: 'Oswald', sans-serif; font-size: 18px; font-weight: 700; color: #fff; }
.price-preview-ttc { font-size: 24px; color: #fff; }

/* ===== RAPPORT KPI ===== */
.rapport-kpi {
  background: var(--navy-xlt); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; text-align: center;
}
.rk-label { font-size: var(--fs-xs); color: var(--text-muted); font-weight: 700; text-transform: uppercase; margin-bottom: 3px; }
.rk-val   { font-weight: 800; font-size: var(--fs-base); color: var(--navy); }

/* ===== BAR CHART ===== */
.bar-chart-wrap {
  display: flex; align-items: flex-end; gap: 8px;
  min-height: 200px; padding-top: 16px;
}
.bar-col-bs { flex: 1; display: flex; flex-direction: column; align-items: center; }
.bar-val-label { font-size: var(--fs-xs); font-weight: 700; color: var(--navy); margin-bottom: 3px; }
.bar-col-track { width: 100%; max-width: 46px; display: flex; align-items: flex-end; height: 160px; }
.bar-col-fill {
  width: 100%; border-radius: 5px 5px 0 0;
  background: linear-gradient(180deg, var(--orange) 0%, var(--orange-dark) 100%);
  min-height: 4px; transition: height 0.7s ease; opacity: 0.9; cursor: pointer;
}
.bar-col-fill:hover { opacity: 1; box-shadow: 0 -4px 12px rgba(232,118,10,0.35); }
.bar-col-label { font-size: var(--fs-xs); color: var(--text-muted); margin-top: 5px; text-align: center; white-space: nowrap; }
.bar-col-sub   { font-size: 10px; color: #aaa; }

/* ===== RESPONSIVE ===== */
@media (max-width: 991.98px) {
  .main-content { margin-left: 0; width: 100%; }
  .sidebar { transform: translateX(-100%); transition: transform 0.25s ease; }
  .sidebar.open { transform: translateX(0); }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--orange); }


/* ===== Statut traite (liste déroulante colorée) ===== */
.statut-traite { border-width: 2px; cursor: pointer; }
.statut-traite-en_cours { background-color:#0d6efd; border-color:#0d6efd; color:#fff; }
.statut-traite-paye     { background-color:#198754; border-color:#198754; color:#fff; }
.statut-traite-impaye   { background-color:#dc3545; border-color:#dc3545; color:#fff; }
.statut-traite-proteste { background-color:#212529; border-color:#212529; color:#fff; }
.statut-traite option   { background:#fff; color:#000; }
tr.table-success > td { background-color:#d1e7dd !important; }
tr.table-danger  > td { background-color:#f8d7da !important; }

/* =============================================
   IMPRESSION (rapports, dépenses, finances, versements)
   ============================================= */
.print-letterhead { display: none; }

@media print {
  @page { size: A4 landscape; margin: 10mm; }

  html { font-size: 11px; }
  body { background: #fff !important; color: #000; overflow: visible !important;
         -webkit-print-color-adjust: exact; print-color-adjust: exact; }

  /* Masquer l'interface */
  .sidebar, .topbar, .sidebar-toggle, .no-print,
  .btn, button, .btn-close, .pagination, .alert-dismissible .btn-close,
  .modal, .modal-backdrop, .dropdown-menu,
  form[method="GET"], form[method="get"], .nav-tabs,
  th:last-child.no-print, td.no-print { display: none !important; }

  /* Pleine largeur */
  .main-content { margin: 0 !important; width: 100% !important; min-height: 0 !important; }
  .page-content { min-height: 0 !important; }
  .page-content { padding: 0 !important; }

  /* En-tête papier */
  .print-letterhead { display: flex !important; align-items: center; justify-content: space-between;
                      gap: 16px; border-bottom: 3px solid var(--orange); padding-bottom: 8px; margin-bottom: 12px; }
  .print-letterhead img { height: 48px; width: auto; }
  .print-letterhead-title { flex: 1; text-align: center; }
  .plt-title { font-family: 'Oswald', sans-serif; font-size: 20px; font-weight: 700; color: var(--navy); text-transform: uppercase; }
  .plt-sub   { font-size: 10px; color: #555; }

  /* Cartes sans ombres, sans coupure au milieu */
  .card { box-shadow: none !important; border: 1px solid #bbb !important; margin-bottom: 10px !important; }
  .card-header { background: #f1f4f9 !important; border-bottom: 1px solid #bbb !important; }

  /* Sections repliées (Détail, onglets) : tout afficher */
  .collapse, .collapsing { display: block !important; height: auto !important; visibility: visible !important; }
  .tab-content > .tab-pane { display: block !important; opacity: 1 !important; }
  /* …sauf les formulaires d'ajout dépliables */
  [id^="form-"].collapse, .collapse.no-print { display: none !important; }
  .tab-pane { break-before: auto; }
  .table-responsive { overflow: visible !important; }

  /* Tableaux */
  table { width: 100% !important; font-size: 10.5px; border-collapse: collapse; }
  thead { display: table-header-group; }   /* répète l'en-tête à chaque page */
  tfoot { display: table-footer-group; }
  tr, img { break-inside: avoid; }
  th, td { padding: 3px 6px !important; }
  a { color: inherit !important; text-decoration: none !important; }
  .badge { border: 1px solid #999; color: #000 !important; background: #fff !important; }
  .table-dark, .table-dark th, .table-dark td { background: var(--navy) !important; color: #fff !important; }


  /* ===== Listes uniquement : on retire ajouts, totaux, graphiques, filtres ===== */
  .page-content .card:not(:has(table)),
  .page-content .card:has(canvas),
  .page-content .stat-card,
  .page-content .alert,
  .card-body:has(> form),
  .card-footer,
  .page-content form[method="POST"]:not(:has(table)) { display: none !important; }
  /* colonnes/rangées devenues vides */
  .page-content .row:not(:has(table)):not(:has(.card)) { display: none !important; }
  .page-content [class*="col-"]:not(:has(table)) { display: none !important; }
  /* listes déroulantes (ex. statut) imprimées comme du texte simple */
  table select { appearance: none; -webkit-appearance: none; border: 0 !important; background: none !important; padding: 0 !important; font-weight: 700; color: #000 !important; }
  canvas { max-width: 100% !important; }
}