/* ===== Base ===== */
body {
  font-family: 'Inter', sans-serif;
}

/* ===== Header ===== */
.gradient-header {
  background: linear-gradient(135deg, #1e3a8a 0%, #4338ca 55%, #6d28d9 100%);
}

.btn-glass {
  padding: 0.5rem 0.9rem;
  border-radius: 0.6rem;
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(6px);
  font-size: 0.85rem;
  font-weight: 500;
  transition: background 0.2s;
}
.btn-glass:hover { background: rgba(255, 255, 255, 0.28); }

/* ===== Onglets ===== */
/* Barre d'onglets défilable horizontalement */
.tabs-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;        /* Firefox */
}
.tabs-scroll::-webkit-scrollbar { display: none; } /* Chrome/Safari */

/* Sur mobile : les onglets passent à la ligne, tous toujours visibles */
@media (max-width: 640px) {
  .tabs-scroll {
    flex-wrap: wrap;
    overflow-x: visible;
    padding-bottom: 2px;
  }
}

.tab-btn {
  padding: 0.65rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.65);
  border-radius: 0.6rem 0.6rem 0 0;
  transition: all 0.2s;
  white-space: nowrap;   /* empêche la coupure du libellé */
  flex-shrink: 0;        /* empêche l'écrasement des onglets */
}
.tab-btn:hover { color: #fff; background: rgba(255, 255, 255, 0.1); }
.tab-btn.active {
  color: #312e81;
  background: #f1f5f9;
}

.tab-panel { animation: fadeIn 0.25s ease; }
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ===== KPI cards ===== */
.kpi-card {
  background: #fff;
  border-radius: 0.9rem;
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.8rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  transition: transform 0.15s, box-shadow 0.15s;
}
.kpi-card:hover { transform: translateY(-2px); box-shadow: 0 6px 16px rgba(0, 0, 0, 0.1); }
.kpi-icon {
  width: 2.6rem; height: 2.6rem;
  border-radius: 0.7rem;
  display: flex; align-items: center; justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}
.kpi-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; color: #64748b; font-weight: 600; }
.kpi-value { font-size: 1.05rem; font-weight: 800; color: #0f172a; }

/* ===== Graphiques ===== */
.chart-card {
  background: #fff;
  border-radius: 0.9rem;
  padding: 1.2rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
}
.chart-title { font-weight: 700; font-size: 0.95rem; color: #1e293b; margin-bottom: 0.9rem; }

/* ===== Toolbar ===== */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  margin-bottom: 1rem;
  align-items: center;
}
.search-icon {
  position: absolute; left: 0.85rem; top: 50%;
  transform: translateY(-50%);
  color: #94a3b8; font-size: 0.85rem;
}
.search-input {
  width: 100%;
  padding: 0.6rem 0.9rem 0.6rem 2.3rem;
  border-radius: 0.7rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  font-size: 0.875rem;
  outline: none;
  transition: border 0.2s, box-shadow 0.2s;
}
.search-input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15); }
.select-field {
  padding: 0.6rem 0.9rem;
  border-radius: 0.7rem;
  border: 1px solid #e2e8f0;
  background: #fff;
  font-size: 0.875rem;
  outline: none;
  cursor: pointer;
}
.select-field:focus { border-color: #6366f1; }

/* ===== Boutons ===== */
.btn-primary {
  padding: 0.6rem 1.1rem;
  background: linear-gradient(135deg, #4f46e5, #6d28d9);
  color: #fff;
  border-radius: 0.7rem;
  font-size: 0.875rem;
  font-weight: 600;
  box-shadow: 0 3px 8px rgba(79, 70, 229, 0.3);
  transition: transform 0.15s, box-shadow 0.15s;
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 6px 14px rgba(79, 70, 229, 0.4); }
.btn-secondary {
  padding: 0.6rem 1.1rem;
  background: #f1f5f9;
  color: #334155;
  border-radius: 0.7rem;
  font-size: 0.875rem;
  font-weight: 600;
  transition: background 0.15s;
}
.btn-secondary:hover { background: #e2e8f0; }
.btn-danger {
  padding: 0.6rem 1.1rem;
  background: #dc2626;
  color: #fff;
  border-radius: 0.7rem;
  font-size: 0.875rem;
  font-weight: 600;
}
.btn-danger:hover { background: #b91c1c; }

/* ===== Tables ===== */
.table-card {
  background: #fff;
  border-radius: 0.9rem;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.07);
  overflow: hidden;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.data-table thead th {
  background: #f8fafc;
  padding: 0.75rem 0.9rem;
  text-align: left;
  font-weight: 700;
  color: #475569;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
  border-bottom: 1px solid #e2e8f0;
}
.data-table thead th { cursor: pointer; user-select: none; }
.data-table thead th:hover { color: #4f46e5; }
.data-table thead th.bulk-col { cursor: default; }
.data-table thead th.bulk-col:hover { color: #475569; }
/* Indicateur de tri générique (tri DOM) */
.data-table thead th.sort-asc::after { content: ' ▲'; font-size: 0.55rem; color: #4f46e5; }
.data-table thead th.sort-desc::after { content: ' ▼'; font-size: 0.55rem; color: #4f46e5; }
.data-table thead th i { font-size: 0.65rem; opacity: 0.5; margin-left: 2px; }
.th-sub { font-size: 0.6rem; font-weight: 500; color: #94a3b8; text-transform: none; letter-spacing: 0; }
.data-table tbody td {
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid #f1f5f9;
  color: #334155;
  white-space: nowrap;
}
.data-table tbody tr { transition: background 0.12s; }
.data-table tbody tr:hover { background: #f0f4ff; }
.data-table tbody tr.row-selected { background: #e0e7ff; }
.data-table tbody tr.row-selected:hover { background: #d7defc; }

/* Pager des grands tableaux (affichage limité pour la rapidité) */
.table-pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  padding: 0.7rem 0.9rem;
  border-top: 1px solid #e2e8f0;
  background: #f8fafc;
}

/* Autocomplete personnalisé (remplace <datalist>, fiable sur mobile) */
.ac-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 200;
  max-height: 240px;
  overflow-y: auto;
  background: #fff;
  border: 1px solid #c7d2fe;
  border-radius: 0.6rem;
  box-shadow: 0 12px 28px rgba(49, 46, 129, 0.18);
  -webkit-overflow-scrolling: touch;
}
.ac-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.65rem 0.9rem;
  font-size: 0.85rem;
  color: #334155;
  cursor: pointer;
  border-bottom: 1px solid #f1f5f9;
}
.ac-item:last-child { border-bottom: none; }
.ac-item i { color: #818cf8; font-size: 0.75rem; }
.ac-item:hover, .ac-item.ac-active { background: #eef2ff; color: #4338ca; }
.ac-empty {
  padding: 0.65rem 0.9rem;
  font-size: 0.78rem;
  font-style: italic;
  color: #94a3b8;
}

/* Barre de progression des traitements groupés */
#bulk-progress {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  align-items: center;
  gap: 0.75rem;
  background: #312e81;
  color: #fff;
  font-size: 1.05rem;
  font-weight: 700;
  padding: 1rem 1.9rem;
  border-radius: 9999px;
  box-shadow: 0 12px 36px rgba(49, 46, 129, 0.5);
  max-width: calc(100vw - 2rem);
}
#bulk-progress i { font-size: 1.15rem; }
.text-right { text-align: right !important; }
.text-center { text-align: center !important; }

/* Badges statut */
.badge {
  display: inline-block;
  padding: 0.22rem 0.65rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
}
.badge-paye { background: #d1fae5; color: #047857; }
.badge-encours { background: #dbeafe; color: #1d4ed8; }
.badge-partiel { background: #fef3c7; color: #b45309; }
.badge-retard { background: #fee2e2; color: #b91c1c; }

/* Badges opérateur */
.badge-op { background: #f3e8ff; color: #7e22ce; }
.badge-entrant { background: #d1fae5; color: #047857; }
.badge-sortant { background: #fee2e2; color: #b91c1c; }

/* Boutons action ligne */
.action-btn {
  width: 1.9rem; height: 1.9rem;
  border-radius: 0.5rem;
  font-size: 0.78rem;
  transition: all 0.15s;
  margin: 0 1px;
}
.action-btn.versement { color: #0d9488; }
.action-btn.versement:hover { background: #ccfbf1; }
.action-btn.view { color: #6366f1; }
.action-btn.view:hover { background: #e0e7ff; }
.action-btn.edit { color: #059669; }
.action-btn.edit:hover { background: #d1fae5; }
.action-btn.delete { color: #dc2626; }
.action-btn.delete:hover { background: #fee2e2; }

/* Montants */
.amount-in { color: #059669; font-weight: 700; }
.amount-out { color: #dc2626; font-weight: 700; }
.amount-warn { color: #b45309; font-weight: 700; }

/* ===== Empty state ===== */
.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: #94a3b8;
}
.empty-state i { font-size: 2.4rem; margin-bottom: 0.6rem; display: block; }

/* ===== Modals ===== */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(3px);
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  overflow-y: auto;
}
.modal-box {
  background: #fff;
  border-radius: 1rem;
  width: 100%;
  max-width: 640px;
  max-height: 92vh;
  overflow-y: auto;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.3);
  animation: modalIn 0.22s ease;
}
@keyframes modalIn {
  from { opacity: 0; transform: scale(0.96) translateY(12px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.4rem;
  border-bottom: 1px solid #f1f5f9;
  position: sticky;
  top: 0;
  background: #fff;
  z-index: 2;
}
.modal-close {
  width: 2rem; height: 2rem;
  border-radius: 0.55rem;
  color: #64748b;
  transition: background 0.15s;
}
.modal-close:hover { background: #f1f5f9; }
.modal-body { padding: 1.3rem 1.4rem; }
.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  margin-top: 1.3rem;
  padding-top: 1rem;
  border-top: 1px solid #f1f5f9;
}

/* Formulaires */
.form-label {
  display: block;
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.3rem;
}
.form-input {
  width: 100%;
  padding: 0.55rem 0.8rem;
  border-radius: 0.6rem;
  border: 1px solid #e2e8f0;
  font-size: 0.875rem;
  outline: none;
  background: #fff;
  transition: border 0.2s, box-shadow 0.2s;
}
.form-input:focus { border-color: #6366f1; box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.14); }

/* ===== Import Excel ===== */
.step-dot {
  padding: 0.35rem 0.8rem;
  border-radius: 999px;
  background: #f1f5f9;
  color: #94a3b8;
}
.step-dot.active { background: #4f46e5; color: #fff; }
.step-dot.done { background: #d1fae5; color: #047857; }

.drop-zone {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 2.6rem 1rem;
  border: 2px dashed #c7d2fe;
  border-radius: 1rem;
  background: #f8faff;
  color: #64748b;
  cursor: pointer;
  transition: all 0.2s;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: #6366f1;
  background: #eef2ff;
}

.mapping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 0.6rem;
  max-height: 300px;
  overflow-y: auto;
  padding-right: 4px;
}
.mapping-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.6rem;
  padding: 0.45rem 0.6rem;
}
.mapping-row .field-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: #334155;
  flex: 1;
  min-width: 0;
}
.mapping-row select {
  flex: 1.2;
  font-size: 0.78rem;
  padding: 0.35rem 0.5rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.45rem;
  background: #fff;
  outline: none;
  min-width: 0;
}
.mapping-row select.mapped { border-color: #10b981; background: #f0fdf4; }

.preview-table { width: 100%; border-collapse: collapse; font-size: 0.72rem; }
.preview-table th {
  background: #f1f5f9;
  padding: 0.4rem 0.6rem;
  text-align: left;
  font-weight: 700;
  color: #475569;
  white-space: nowrap;
  border-bottom: 1px solid #e2e8f0;
}
.preview-table td {
  padding: 0.35rem 0.6rem;
  border-bottom: 1px solid #f1f5f9;
  white-space: nowrap;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Caisse : cartes comptes */
.compte-card {
  background: #fff;
  border: 1px solid #e2e8f0;
  border-radius: 0.8rem;
  padding: 0.8rem;
  cursor: pointer;
  transition: transform 0.15s, box-shadow 0.15s, border-color 0.15s;
}
.compte-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.09);
  border-color: #c7d2fe;
}

/* Badge frais */
.badge-frais { background: #f1f5f9; color: #475569; }

/* Synthèse : ligne total */
.synthese-total td {
  background: #eef2ff;
  border-top: 2px solid #c7d2fe;
  padding: 0.8rem 0.9rem;
  font-size: 0.85rem;
}

/* Badge mode versement */
.badge-mode { background: #ccfbf1; color: #0f766e; }

/* Historique versements dans détail */
.versement-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.6rem;
  padding: 0.5rem 0.7rem;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 0.6rem;
}

/* ===== Écran de connexion ===== */
.login-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: linear-gradient(135deg, #1e3a8a 0%, #4338ca 55%, #6d28d9 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.login-card {
  background: #fff;
  border-radius: 1.2rem;
  padding: 2rem 1.8rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  animation: modalIn 0.3s ease;
}
.login-input { padding-left: 2.4rem !important; }
.login-input-icon {
  position: absolute; left: 0.85rem; top: 50%;
  transform: translateY(-50%);
  color: #94a3b8; font-size: 0.85rem;
}

/* Pastille utilisateur connecté (header) */
.user-chip {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.15);
  border-radius: 999px;
  padding: 0.3rem 0.4rem 0.3rem 0.7rem;
}
.user-chip-logout {
  width: 1.8rem; height: 1.8rem;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.15);
  font-size: 0.75rem;
  transition: background 0.15s;
}
.user-chip-logout:hover { background: rgba(239, 68, 68, 0.8); }

/* Onglets réservés à l'administrateur */
.tab-btn.admin-only { display: none; }
body.role-admin .tab-btn.admin-only { display: block; }

/* Rôle Lecture seule (Auditeur) : masque tous les boutons d'écriture */
body.role-lecture #btn-add-paiement,
body.role-lecture #btn-add-momo,
body.role-lecture #btn-add-versement,
body.role-lecture #btn-add-operation,
body.role-lecture #btn-add-compte,
body.role-lecture #btn-add-obm,
body.role-lecture #btn-add-affaire,
body.role-lecture #btn-add-recette,
body.role-lecture #btn-add-csm,
body.role-lecture #btn-add-pa,
body.role-lecture #btn-import,
body.role-lecture .action-btn.edit,
body.role-lecture .action-btn.delete,
body.role-lecture .action-btn.versement { display: none; }

/* ===== Sous-onglets des espaces de travail ===== */
.espace-btn {
  padding: 0.45rem 0.9rem;
  border-radius: 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: #475569;
  background: #fff;
  border: 1px solid #e2e8f0;
  transition: all 0.15s;
  white-space: nowrap;
}
.espace-btn:hover { background: #eef2ff; color: #4338ca; border-color: #c7d2fe; }
.espace-btn.active {
  background: linear-gradient(135deg, #4f46e5, #7c3aed);
  color: #fff;
  border-color: transparent;
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.35);
}

/* Badge « Annulé/contre-passé » + ligne d'opération annulée */
.badge-annule { background: #f3e8ff; color: #7e22ce; }
.op-annulee td { opacity: 0.55; text-decoration: line-through; }
.op-annulee td:last-child, .op-annulee td .badge { text-decoration: none; }

/* ---------- Pièces jointes (PJ) ---------- */
.pj-item {
  display: flex; align-items: center; gap: 0.5rem;
  background: #fff; border: 1px solid #e2e8f0; border-radius: 0.5rem;
  padding: 0.35rem 0.5rem;
}
.pj-thumb {
  width: 34px; height: 34px; object-fit: cover; border-radius: 0.375rem;
  border: 1px solid #e2e8f0; flex-shrink: 0; background: #f8fafc;
}
.pj-thumb-icon {
  display: inline-flex; align-items: center; justify-content: center;
  color: #64748b;
}
.pj-link {
  display: inline-flex; align-items: center; gap: 0.2rem;
  font-size: 10px; font-weight: 600; color: #4f46e5;
  background: #eef2ff; border: 1px solid #c7d2fe; border-radius: 9999px;
  padding: 0.1rem 0.45rem; margin: 0.08rem 0.12rem 0.08rem 0;
  max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.pj-link:hover { background: #e0e7ff; }
.pj-card {
  display: block; border: 1px solid #e2e8f0; border-radius: 0.6rem;
  padding: 0.4rem; background: #fff; transition: box-shadow 0.15s;
}
.pj-card:hover { box-shadow: 0 4px 12px rgba(79, 70, 229, 0.12); }
.pj-detail-img {
  width: 100%; height: 90px; object-fit: cover; border-radius: 0.4rem;
  background: #f1f5f9; margin-bottom: 0.25rem;
  display: flex; align-items: center; justify-content: center;
}

/* Badges statuts supplémentaires */
.badge-attente { background: #e2e8f0; color: #475569; }
.badge-recu { background: #ccfbf1; color: #0f766e; }

/* ===== Toast ===== */
.toast {
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  background: #0f172a;
  color: #fff;
  padding: 1.05rem 1.9rem;
  border-radius: 1rem;
  font-size: 1.08rem;
  font-weight: 600;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.4);
  z-index: 9999;
  animation: toastIn 0.25s ease;
  max-width: calc(100vw - 2rem);
  text-align: center;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 12px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}
.toast.success { background: #047857; }
.toast.error { background: #b91c1c; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
  .kpi-value { font-size: 0.9rem; }
  .tab-btn { padding: 0.55rem 0.7rem; font-size: 0.78rem; }
}
