/* ======================================= */
/* 1. Base & Réinitialisation              */
/* ======================================= */
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600;700&display=swap");

:root {
  --primary-color: #4c51bf; /* Bleu Indigo */
  --secondary-color: #4a5568; /* Gris foncé */
  --accent-color: #38a169; /* Vert pour succès */
  --danger-color: #e53e3e; /* Rouge pour danger */
  --bg-light: #f7fafc; /* Arrière-plan très clair */
  --text-dark: #2d3748;
  --border-light: #cbd5e0;
  --box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: "Poppins", sans-serif;
}

body {
  font-family: "Poppins", sans-serif;
  background-color: var(--bg-light);
  color: var(--text-dark);
  line-height: 1.6;
  padding: 20px;
}

.container {
  max-width: 1200;
  width: 100%;
  margin: 0 auto;
  background-color: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);
  padding: 30px;
}

/* ======================================= */
/* 2. Header et Titres                     */
/* ======================================= */
.header {
  text-align: center;
  margin-bottom: 30px;
  padding-bottom: 20px;
  border-bottom: 1px solid var(--border-light);
}

.header h1 {
  color: var(--primary-color);
  font-weight: 700;
  font-size: 2.5em;
  margin-bottom: 5px;
}

.header p {
  color: var(--secondary-color);
  font-size: 1.1em;
}

.content-box {
  padding: 20px;
  border-radius: 8px;
  background: #fff;
}

.content-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  padding-bottom: 10px;
  border-bottom: 2px solid #edf2f7;
}

.content-header h2 {
  color: var(--primary-color);
  font-weight: 600;
  font-size: 1.8em;
}

/* ======================================= */
/* 3. Boutons et Formulaires               */
/* ======================================= */
button {
  cursor: pointer;
  transition: all 0.2s ease-in-out;
  border-radius: 6px;
  font-weight: 600;
}

.btn-primary {
  display: flex;
  justify-content: center;
  align-items: center;
  background-color: var(--primary-color);
  color: white;
  border: none;
  gap: 10px;
  padding: 10px 20px;
}

.btn-primary:hover {
  background-color: #3c4295;
  box-shadow: var(--box-shadow);
}

.btn-primary img{
    width: 15px;
}

.btn-secondary {
  background-color: var(--border-light);
  color: var(--text-dark);
  border: 1px solid var(--border-light);
  padding: 10px 20px;
}

.btn-secondary:hover {
  background-color: #e2e8f0;
}

.btn-edit {
  background-color: #faf089;
  color: var(--text-dark);
  border: none;
  padding: 5px 10px;
  font-size: 0.9em;
  margin-right: 5px;
}

.btn-delete {
  background-color: var(--danger-color);
  color: white;
  border: none;
  padding: 5px 10px;
  font-size: 0.9em;
}

.btn-delete:hover {
  background-color: #c53030;
}

/* Formulaires */
.form-container {
  background: var(--bg-light);
  padding: 25px;
  border-radius: 8px;
  margin-bottom: 30px;
  border: 1px solid var(--border-light);
  display: none; /* Caché par défaut */
  opacity: 0;
  transform: translateY(-20px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

.form-container.active {
  display: block;
  opacity: 1;
  transform: translateY(0);
}

.form-group {
  margin-bottom: 15px;
}

.form-group label {
  display: block;
  margin-bottom: 5px;
  font-weight: 600;
  color: var(--secondary-color);
}

input[type="text"],
input[type="number"],
input[type="email"],
input[type="tel"],
input[type="date"],
select,
textarea {
  width: 100%;
  padding: 12px;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  font-size: 1em;
  font-family: inherit;
  transition: border-color 0.2s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--primary-color);
  outline: none;
  box-shadow: 0 0 0 1px var(--primary-color);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 20px;
}

.form-actions {
  margin-top: 25px;
  display: flex;
  gap: 10px;
}

/* ======================================= */
/* 4. Navigation et Onglets                */
/* ======================================= */
.tabs {
  display: flex;
  justify-content: flex-start;
  margin-bottom: 30px;
  border-bottom: 3px solid var(--border-light);
}

.tab-btn {
  padding: 15px 25px;
  border: none;
  background: transparent;
  color: var(--secondary-color);
  font-size: 1.1em;
  font-weight: 600;
  border-bottom: 3px solid transparent;
  transition: border-color 0.3s, color 0.3s;
}

.tab-btn:hover {
  color: var(--primary-color);
  background-color: var(--bg-light);
}

.tab-btn.active {
  color: var(--primary-color);
  border-bottom: 3px solid var(--primary-color);
  background-color: var(--bg-light);
}

.tab-content {
  display: none;
  padding: 20px 0;
}

.tab-content.active {
  display: block;
}

/* ======================================= */
/* 5. Dashboard et Statistiques            */
/* ======================================= */
.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 25px;
  padding: 10px;
}

.quartier-card {
  background: white;
  border-radius: 10px;
  padding: 25px;
  box-shadow: var(--box-shadow);
  transition: transform 0.2s, box-shadow 0.2s;
  border-left: 5px solid var(--primary-color);
}

.quartier-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
}

.quartier-card h3 {
  color: var(--primary-color);
  font-size: 1.4em;
  margin-bottom: 20px;
  border-bottom: 1px dashed var(--border-light);
  padding-bottom: 10px;
}

.stat-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px dotted #e2e8f0;
  font-size: 0.95em;
}

.stat-label {
  color: var(--secondary-color);
}

.stat-value {
  font-weight: 600;
}

.montant-total {
  color: var(--accent-color);
}

.montant-impaye {
  color: var(--danger-color);
}

/* ======================================= */
/* 6. Listes et Cartes (Structures/Quartiers) */
/* ======================================= */
.structure-card {
  background: #fff;
  border: 1px solid var(--border-light);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 15px;
  transition: border-color 0.2s;
}

.structure-card:hover {
  border-color: var(--primary-color);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.05);
}

.structure-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
}

.structure-name {
  font-size: 1.3em;
  font-weight: 600;
  color: var(--text-dark);
  margin-bottom: 5px;
}

.quartier-badge {
  display: inline-block;
  background-color: var(--primary-color);
  color: white;
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 0.8em;
  font-weight: 600;
  margin-bottom: 10px;
}

.structure-info {
  font-size: 0.9em;
  color: var(--secondary-color);
  margin-top: 3px;
}

/* Recherche et Filtre */
.search-filter {
  display: flex;
  gap: 15px;
  margin-bottom: 30px;
}

.search-input {
  flex-grow: 1;
}

.filter-select {
  width: 250px;
}

/* ======================================= */
/* 7. Tableau (Factures)                   */
/* ======================================= */
.data-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  margin-top: 20px;
  box-shadow: var(--box-shadow);
  border-radius: 8px;
  overflow: hidden; /* Pour que les coins arrondis fonctionnent */
}

.data-table th,
.data-table td {
  padding: 15px;
  text-align: left;
  border-bottom: 1px solid #edf2f7;
}

.data-table th {
  background-color: var(--primary-color);
  color: white;
  font-weight: 600;
  font-size: 0.95em;
  text-transform: uppercase;
}

.data-table tbody tr:last-child td {
  border-bottom: none;
}

.data-table tbody tr:nth-child(even) {
  background-color: var(--bg-light);
}

.data-table tbody tr:hover {
  background-color: #e2e8f0;
}

/* Badges de Statut */
.status-badge {
  display: inline-block;
  padding: 5px 10px;
  border-radius: 20px;
  font-weight: 600;
  font-size: 0.85em;
  text-transform: capitalize;
}

.status-payee {
  background-color: #c6f6d5; /* Vert clair */
  color: var(--accent-color); /* Vert foncé */
}

.status-impayee {
  background-color: #fed7d7; /* Rouge clair */
  color: var(--danger-color); /* Rouge foncé */
}

.status-retard {
  background-color: #fefcbf; /* Jaune clair */
  color: #975a16; /* Marron/Orange foncé */
}

/* ======================================= */
/* 8. Modales (Facture unique & Liste de quartier) */
/* ======================================= */

/* Styles généraux de la modale */
.modal {
  display: none;
  position: fixed;
  z-index: 1000;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  overflow: auto;
  background-color: rgba(0, 0, 0, 0.6); /* Fond semi-transparent */
  padding-top: 50px;
  opacity: 0;
  transition: opacity 0.3s ease;
  align-items: center;
  justify-content: center;
}

.modal.show {
  display: flex;
  opacity: 1;
  padding: 20px;
  padding-top: 0;
}

.modal-content {
  background-color: #fefefe;
  margin: 5% auto; /* Centrage */
  padding: 30px;
  border: 1px solid #888;
  width: 90%;
  max-width: 800px; /* Taille max par défaut (pour la vue facture) */
  border-radius: 10px;
  box-shadow: 0 4px 10px rgba(0, 0, 0, 0.2);
  position: relative;
  max-height: 90vh; /* Permet un scroll si nécessaire */
  overflow-y: auto;
}

/* Styles spécifiques pour la modale de quartier (plus large) */
#quartierFacturesModal .modal-content {
  max-width: 1200px;
}

/* Header de modale commun */
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 25px;
  border-bottom: 3px solid var(--primary-color);
  padding-bottom: 15px;
}

.modal-header h2 {
  color: var(--primary-color);
  margin: 0;
}

.modal-actions {
  display: flex;
  gap: 10px;
}

/* Grille de stats pour la modale de quartier */
.modal-stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 15px;
  margin-bottom: 25px;
  background: #f0f4ff; /* Couleur de fond plus claire */
  padding: 20px;
  border-radius: 10px;
  border: 1px solid #dce3f3;
}

.modal-stats-grid > div > div:first-child {
  color: var(--secondary-color);
  font-size: 0.9em;
  margin-bottom: 5px;
}

.modal-stats-grid > div > div:last-child {
  font-size: 1.5em;
  font-weight: 700;
  color: var(--text-dark);
}

/* Couleurs spécifiques pour les stats de modale */
.stat-value-blue {
  color: var(--primary-color);
}
.stat-value-green {
  color: var(--accent-color);
}
.stat-value-red {
  color: var(--danger-color);
}

/* Tableau dans la modale */
.modal-table-container {
  overflow-x: auto; /* Scroll horizontal si tableau trop large */
}

.modal table {
  margin-top: 15px;
  width: 100%;
  border-collapse: collapse;
}

.modal table th {
  background-color: var(--primary-color);
  color: white;
  font-weight: 600;
  padding: 12px;
}

.modal table td {
  padding: 12px;
  border-bottom: 1px solid #edf2f7;
  text-align: left;
}

.modal td.text-right {
  text-align: right;
}
.modal td.text-center {
  text-align: center;
}

/* ======================================= */
/* 9. Responsivité et Impression           */
/* ======================================= */

@media (max-width: 1024px) {
  .container {
    padding: 20px;
  }
  .data-table thead {
    display: none;
  }

  .data-table,
  .data-table tbody,
  .data-table tr,
  .data-table td {
    display: block;
    width: 100%;
  }

  .data-table tr {
    margin-bottom: 15px;
    border: 1px solid var(--border-light);
    border-radius: 8px;
  }

  .data-table td {
    text-align: right !important;
    padding-left: 50% !important;
    position: relative;
    border-bottom: 1px dotted var(--border-light);
  }

  .data-table td::before {
    content: attr(data-label);
    position: absolute;
    left: 15px;
    width: 45%;
    padding-right: 10px;
    white-space: nowrap;
    font-weight: 600;
    color: var(--secondary-color);
    text-align: left;
  }

  /* Adapter les boutons du tableau pour mobile */
  .data-table td:last-child {
    text-align: center !important;
    display: flex;
    justify-content: center;
    gap: 10px;
    padding-left: 15px !important;
  }

  .search-filter {
    flex-direction: column;
  }

  .filter-select {
    width: 100%;
  }

  /* Modale de quartier en responsive */
  .modal-content-large {
    max-width: 95%;
  }
}

@media (max-width: 768px) {
  .header h1 {
    font-size: 1.8em;
  }
  .header p {
    font-size: 1em;
  }
  .tabs {
   
   
    overflow-x: auto;
    white-space: nowrap;
    -webkit-overflow-scrolling: touch;
    justify-content: initial;
  }
  .tab-btn {
    flex-shrink: 0;
    padding: 12px 18px;
    font-size: 1em;
  }
  .form-grid {
    grid-template-columns: 1fr;
   
  }
  .content-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .content-header button {
    margin-top: 15px;
  }

 .structure-header {
        flex-direction: column; 
        align-items: stretch;
    }
    .structure-header > div:last-child {
        margin-top: 15px; 
        display: flex;
        justify-content: space-around; 
        gap: 5px;
    }
    .structure-header button {
        margin-left: 0;
        flex: 1; 
        font-size: 0.9em;
        padding: 8px 5px;
    }

    
    td[data-label="Actions"] {
       
        display: flex;
        flex-direction: column; 
        gap: 5px;
        align-items: flex-end; 
        min-width: 120px; 
    }
    
    
    td[data-label="Actions"] button {
        width: 50%;
        margin: 0 !important; 
    }


    #facturesTable table {
        min-width: 700px; 
    }

 



 
}

/* Styles d'impression (pour masquer la navigation et les boutons non pertinents) */
@media print {
  /* Masquer tout ce qui n'est pas le contenu de la modale de vue */
  body > .container,
  .modal-actions,
  .tabs,
  .btn-delete,
  .btn-edit,
  .footer-container,
  #quartierFacturesModal {
    /* Masque la modale de liste si elle est ouverte */
    display: none !important;
  }

  /* Afficher la modale de vue en tant que corps principal */
  #factureViewModal {
    /* Cible uniquement la modale de vue pour l'impression */
    position: static !important;
    background: none !important;
    display: block !important;
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible;
  }

  #factureViewModal .modal-content {
    margin: 0 !important;
    width: auto !important;
    max-width: none !important;
    border: none !important;
    box-shadow: none !important;
    padding: 0 !important;
    overflow: visible;
  }

  /* Le contenu réel de la facture est affiché */
  #factureViewModal #factureDetailsContent {
    display: block !important;
  }
}



footer {
  background-color: var(--primary-color);
  color: white;
  padding: 30px 20px;
  margin-top: auto;
}

.footer-container {
  max-width: 1200px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
}

.footer-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 2px;
}

.footer-brand .icon {
  width: 40px;
  height: 40px;
  background: rgba(255, 255, 255, 0.2);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.footer-divider {
  width: 60px;
  height: 2px;
  background: rgba(255, 255, 255, 0.3);
  border-radius: 2px;
}

.footer-info {
  text-align: center;
  font-size: 14px;
  color: rgba(255, 255, 255, 0.9);
  line-height: 1.6;
}

.footer-developer {
  font-size: 13px;
  color: rgba(255, 255, 255, 0.7);
  font-style: italic;
}

.footer-developer span {
  color: rgba(255, 255, 255, 0.95);
  font-weight: 600;
  font-style: normal;
}

.footer-bottom {
  font-size: 12px;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 10px;
}

@media (max-width: 768px) {
  .footer-brand {
    font-size: 20px;
  }

  .footer-brand .icon {
    width: 35px;
    height: 35px;
    font-size: 18px;
  }

  
}
