/* ══════════════════════════════════════════════
   APP.CSS — Styles de la page principale (index.html)
   ══════════════════════════════════════════════ */

/* --- RESET ---
   Supprime les marges et paddings par défaut du navigateur */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* --- VARIABLES DE COULEUR ---
   Mêmes couleurs que login.css + quelques ajouts */
:root {
  --green:       #007E64;       /* Vert principal */
  --green-dark:  #005c49;       /* Vert foncé (survol) */
  --green-light: #e6f4f1;       /* Vert très clair */
  --text:        #1a1a1a;       /* Texte principal */
  --text-muted:  #6b7280;       /* Texte secondaire (gris) */
  --border:      #d1d5db;       /* Bordures */
  --white:       #ffffff;
  --bg:          #f5f7f6;       /* Fond de page */
  --sidebar-w:   240px;         /* Largeur de la barre latérale */
  --orange:      #f59e0b;       /* Orange (alertes "à rendre bientôt") */
  --red:         #ef4444;       /* Rouge (alertes "en retard") */
}

html, body { height: 100%; font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); }


/* ══════════════════════════════════════════════
   MISE EN PAGE GÉNÉRALE
   Le site est divisé en : sidebar (gauche) + main (droite)
   ══════════════════════════════════════════════ */

.layout { display: flex; min-height: 100vh; }


/* ══════════════════════════════════════════════
   SIDEBAR — Barre latérale verte à gauche
   Contient : logo, navigation, infos utilisateur
   ══════════════════════════════════════════════ */

.sidebar {
  width: var(--sidebar-w); background: var(--green);
  display: flex; flex-direction: column;
  /* "position: fixed" = la sidebar reste visible même quand on scrolle */
  position: fixed; top: 0; left: 0; bottom: 0; z-index: 100;
}

/* En-tête de la sidebar : logo + nom */
.sidebar-brand {
  padding: 24px 20px 20px;
  border-bottom: 1px solid rgba(255,255,255,0.12);
  display: flex; align-items: center; gap: 10px;
}
.sidebar-brand img { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; }
.sidebar-brand-name { font-family: 'DM Serif Display', serif; color: #fff; font-size: 17px; }

/* Zone de navigation (les onglets : Inventaire, Contrats, etc.) */
.sidebar-nav { flex: 1; padding: 14px 10px; }

/* Chaque onglet de navigation */
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; border-radius: 8px;
  color: rgba(255,255,255,0.72); font-size: 13.5px; font-weight: 500;
  cursor: pointer; transition: all 0.15s; margin-bottom: 2px; user-select: none;
}
.nav-item:hover  { background: rgba(255,255,255,0.1); color: #fff; }
.nav-item.active { background: rgba(255,255,255,0.18); color: #fff; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }

/* Pied de la sidebar : nom de l'utilisateur connecté + bouton déconnexion */
.sidebar-footer { padding: 14px 18px; border-top: 1px solid rgba(255,255,255,0.12); }
.user-name { color: #fff; font-size: 13px; font-weight: 500; }
.user-sub  { color: rgba(255,255,255,0.55); font-size: 11px; margin-top: 2px; }

/* Badge "Admin" affiché sous le nom si l'utilisateur est admin */
.admin-badge {
  display: inline-block; margin-top: 5px;
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.25);
  border-radius: 12px; padding: 2px 9px; font-size: 10.5px;
  color: rgba(255,255,255,0.85); letter-spacing: 0.04em;
}

/* Bouton "Se déconnecter" */
.btn-logout {
  margin-top: 10px; width: 100%; padding: 7px 12px;
  background: rgba(255,255,255,0.1); border: 1px solid rgba(255,255,255,0.2);
  border-radius: 7px; color: rgba(255,255,255,0.85);
  font-family: 'DM Sans', sans-serif; font-size: 12px; cursor: pointer;
  transition: background 0.15s;
}
.btn-logout:hover { background: rgba(255,255,255,0.18); }


/* ══════════════════════════════════════════════
   ZONE PRINCIPALE (à droite de la sidebar)
   ══════════════════════════════════════════════ */

/* "margin-left" décale le contenu pour ne pas être caché par la sidebar fixe */
.main { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }

/* En-tête de la zone principale (titre + sous-titre de l'onglet actif)
   "position: sticky" = reste collé en haut quand on scrolle */
.main-header {
  background: var(--white); border-bottom: 1px solid var(--border);
  padding: 18px 32px;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 10;
}
.main-header h1 { font-family: 'DM Serif Display', serif; font-size: 21px; font-weight: 400; }
.main-header p  { font-size: 12px; color: var(--text-muted); margin-top: 2px; }

/* Zone de contenu scrollable */
.main-content { padding: 28px 32px; flex: 1; }


/* ══════════════════════════════════════════════
   VISIBILITÉ SELON LE RÔLE / LES CAPACITÉS
   app.js pose sur <body> les classes :
     - role-systeme       (admin système)
     - role-asso          (n'importe quel membre d'une asso)
     - can-write          (admin asso + maintainer)
     - can-manage-members (admin asso uniquement)
     - can-view-logs      (tout sauf viewer)

   Les éléments du HTML utilisent les classes suivantes :
     - .systeme-only             → visible UNIQUEMENT si role-systeme
     - .asso-only                → visible UNIQUEMENT si role-asso
     - .requires-write           → caché si l'utilisateur n'a pas can-write (viewer + admin sys)
     - .requires-manage-members  → caché sauf pour admin d'asso
     - .requires-logs            → caché pour le viewer
   ══════════════════════════════════════════════ */

/* On cache les éléments réservés au rôle opposé */
body:not(.role-systeme) .systeme-only { display: none !important; }
body:not(.role-asso)    .asso-only    { display: none !important; }

/* On cache les éléments qui demandent une capacité absente */
body:not(.can-write)           .requires-write           { display: none !important; }
body:not(.can-manage-members)  .requires-manage-members  { display: none !important; }
body:not(.can-view-logs)       .requires-logs            { display: none !important; }

/* ALIAS de compatibilité (pour ne pas tout réécrire d'un coup) :
   - admin-only  = systeme-only
   - membre-only = asso-only */
body:not(.role-systeme) .admin-only  { display: none !important; }
body:not(.role-asso)    .membre-only { display: none !important; }


/* ══════════════════════════════════════════════
   ONGLETS PRINCIPAUX (Inventaire / Contrats / Factures / Logs)
   Un seul onglet est visible à la fois (celui avec la classe "active")
   ══════════════════════════════════════════════ */

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


/* ══════════════════════════════════════════════
   BOUTONS
   ══════════════════════════════════════════════ */

/* Style de base commun à tous les boutons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 15px; border-radius: 8px;
  font-family: 'DM Sans', sans-serif; font-size: 13px; font-weight: 500;
  cursor: pointer; border: none; transition: all 0.15s;
}
/* Bouton vert plein (actions principales) */
.btn-primary { background: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-dark); }
/* Petit bouton (utilisé dans les tableaux) */
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 6px; }
/* Bouton avec bordure (ex: "Annuler" dans les modals) */
.btn-outline { background: var(--white); color: var(--text); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--green); color: var(--green); }
/* Bouton rouge (supprimer) */
.btn-danger  { background: #fef2f2; color: var(--red); border: 1px solid #fca5a5; }
.btn-danger:hover  { background: #fee2e2; }
/* Bouton vert clair (conclure un contrat) */
.btn-success { background: var(--green-light); color: var(--green); border: 1px solid rgba(0,126,100,0.3); }
.btn-success:hover { background: #c8e8e2; }
/* Bouton orange (allonger un contrat) */
.btn-orange  { background: #fffbeb; color: #92400e; border: 1px solid #fde68a; }
.btn-orange:hover  { background: #fef3c7; }


/* ══════════════════════════════════════════════
   CARTES DE STATISTIQUES (onglet Contrats, vue membre)
   Grille de 4 cartes : Prêts actifs, Emprunts actifs, À rendre bientôt, En retard
   ══════════════════════════════════════════════ */

.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat-card { background: var(--white); border: 1px solid var(--border); border-radius: 10px; padding: 16px 18px; }
.stat-label { font-size: 11px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: 0.05em; }
.stat-value { font-size: 26px; font-weight: 600; margin-top: 4px; color: var(--text); }
/* Couleur du chiffre selon le type de carte */
.stat-card.green  .stat-value { color: var(--green); }
.stat-card.orange .stat-value { color: var(--orange); }
.stat-card.red    .stat-value { color: var(--red); }


/* ══════════════════════════════════════════════
   TABLEAUX
   Utilisés partout : inventaire, contrats, factures, logs
   ══════════════════════════════════════════════ */

/* Conteneur blanc avec bordure arrondie autour du tableau */
.table-wrap { background: var(--white); border: 1px solid var(--border); border-radius: 10px; overflow: hidden; margin-bottom: 24px; }

/* En-tête du tableau (titre + bouton éventuel) */
.table-header {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.table-title    { font-size: 13.5px; font-weight: 600; }
.table-subtitle { font-size: 11.5px; color: var(--text-muted); margin-top: 2px; }

/* Le tableau lui-même */
table { width: 100%; border-collapse: collapse; }
/* En-têtes de colonnes (gris, majuscules) */
th {
  padding: 9px 14px; text-align: left;
  font-size: 11px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.05em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); background: #fafafa;
}
/* Cellules de données */
td { padding: 11px 14px; font-size: 13px; border-bottom: 1px solid #f0f0f0; vertical-align: middle; }
/* Pas de bordure sous la dernière ligne */
tr:last-child td { border-bottom: none; }
/* Effet de survol sur les lignes */
tr:hover td { background: #fafafa; }
/* Cellule contenant plusieurs boutons d'action */
.actions-cell { display: flex; gap: 5px; }


/* ══════════════════════════════════════════════
   BLOCS PAR ASSOCIATION (inventaire, vue admin)
   Chaque asso a son propre tableau séparé par un label
   ══════════════════════════════════════════════ */

.asso-block { margin-bottom: 20px; }
.asso-label {
  font-size: 12px; font-weight: 600; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  margin-bottom: 8px; padding-left: 2px;
  display: flex; align-items: center; gap: 8px;
}
/* Ligne horizontale après le nom de l'asso */
.asso-label::after { content: ''; flex: 1; height: 1px; background: var(--border); }


/* ══════════════════════════════════════════════
   BADGES DE STATUT
   Pastilles colorées : "Actif" (vert), "À rendre bientôt" (orange), "En retard" (rouge)
   ══════════════════════════════════════════════ */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 8px; border-radius: 20px; font-size: 11px; font-weight: 500;
}
/* Point coloré à gauche du texte */
.badge-dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
/* Variantes de couleur */
.badge-green  { background: var(--green-light); color: var(--green); }
.badge-green  .badge-dot { background: var(--green); }
.badge-orange { background: #fffbeb; color: #92400e; }
.badge-orange .badge-dot { background: var(--orange); }
.badge-red    { background: #fef2f2; color: #991b1b; }
.badge-red    .badge-dot { background: var(--red); }
.badge-gray   { background: #f3f4f6; color: #6b7280; }
.badge-gray   .badge-dot { background: #9ca3af; }


/* ══════════════════════════════════════════════
   SOUS-ONGLETS (Actifs / Historique dans Contrats)
   ══════════════════════════════════════════════ */

.section-tabs {
  display: flex; gap: 3px; margin-bottom: 22px;
  background: var(--white); border: 1px solid var(--border);
  border-radius: 9px; padding: 4px; width: fit-content;
}
.section-tab {
  padding: 6px 14px; border-radius: 6px; font-size: 13px; font-weight: 500;
  cursor: pointer; color: var(--text-muted); transition: all 0.15s;
}
/* Le sous-onglet actif a un fond vert */
.section-tab.active { background: var(--green); color: #fff; }
.section-content { display: none; }
.section-content.active { display: block; }


/* ══════════════════════════════════════════════
   MODALS (fenêtres popup)
   Utilisées pour : ajouter un article, créer un contrat, émettre une facture
   ══════════════════════════════════════════════ */

/* Fond semi-transparent qui couvre toute la page */
.modal-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(0,0,0,0.4); z-index: 200;
  align-items: center; justify-content: center;
}
/* Quand le modal est ouvert, on passe en display: flex pour le centrer */
.modal-overlay.open { display: flex; }

/* La fenêtre blanche du modal */
.modal {
  background: var(--white); border-radius: 12px; padding: 26px;
  width: 100%; max-width: 480px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.15); max-height: 90vh; overflow-y: auto;
}
.modal h3 { font-family: 'DM Serif Display', serif; font-size: 19px; font-weight: 400; margin-bottom: 18px; }

/* Champs dans les modals */
.modal-field { margin-bottom: 14px; }
.modal-field label { display: block; font-size: 12px; font-weight: 500; margin-bottom: 5px; }
.modal-field input, .modal-field select, .modal-field textarea {
  width: 100%; padding: 8px 11px;
  border: 1.5px solid var(--border); border-radius: 7px;
  font-family: 'DM Sans', sans-serif; font-size: 13px; color: var(--text);
  outline: none; transition: border-color 0.2s; background: var(--white);
}
.modal-field input:focus, .modal-field select:focus, .modal-field textarea:focus { border-color: var(--green); }
.modal-field textarea { resize: vertical; min-height: 70px; }

/* Ligne avec 2 champs côte à côte (ex: date début + date fin) */
.modal-row     { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
/* Boutons en bas du modal (Annuler + Créer) */
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 20px; }
/* Encadré d'information dans le modal */
.modal-info    { background: var(--bg); border-radius: 7px; padding: 10px 13px; font-size: 12px; color: var(--text-muted); margin-bottom: 14px; line-height: 1.6; }


/* ══════════════════════════════════════════════
   ÉTAT VIDE — Placeholder affiché quand un tableau n'a pas (encore) de données
   Sera automatiquement écrasé par le JS dès que l'API Flask renvoie des données.
   ══════════════════════════════════════════════ */
.empty-row td       { text-align: center; color: var(--text-muted); font-style: italic; padding: 28px 16px; }
.empty-placeholder  { text-align: center; color: var(--text-muted); font-style: italic; padding: 32px 16px; background: var(--white); border-radius: 8px; border: 1px dashed var(--border); }


/* ══════════════════════════════════════════════
   BADGE COMPTEUR — petite pastille rouge avec un nombre
   utilisée à côté de "À valider" pour indiquer le nombre d'éléments en attente.
   Reste vide par défaut ; rempli par JS (ex: "3"). Si vide, ne s'affiche pas.
   ══════════════════════════════════════════════ */
.badge-count        { display: none; min-width: 18px; height: 18px; padding: 0 6px; background: var(--red); color: var(--white); border-radius: 9px; font-size: 11px; font-weight: 600; line-height: 18px; text-align: center; margin-left: 6px; vertical-align: middle; }
.badge-count:not(:empty) { display: inline-block; }


/* ══════════════════════════════════════════════
   BADGES DE STATUT — couleurs selon le statut d'un contrat
   Générés par api.js via la fonction badge() : <span class="badge badge-<statut>">...
   ══════════════════════════════════════════════ */
.badge-actif            { background: var(--green-light); color: var(--green); }
.badge-a_rendre_bientot { background: #fffbeb; color: #92400e; }   /* orange clair */
.badge-en_retard        { background: #fef2f2; color: #991b1b; }   /* rouge clair */
.badge-cloture          { background: #f3f4f6; color: #6b7280; }   /* gris */
.badge-a_valider        { background: #eff6ff; color: #1e40af; }   /* bleu clair */


/* ══════════════════════════════════════════════
   TEXTE EN GRIS — utilisé pour les valeurs "en attente", "—", etc.
   ══════════════════════════════════════════════ */
.muted { color: var(--text-muted); font-style: italic; font-size: 12px; }


/* ══════════════════════════════════════════════
   BADGE "(vous)" — indique la ligne du membre connecté dans le tableau Membres
   ══════════════════════════════════════════════ */
.badge-self { display: inline-block; padding: 1px 6px; background: var(--green-light); color: var(--green); border-radius: 4px; font-size: 10px; font-weight: 600; margin-left: 4px; vertical-align: middle; }


/* ══════════════════════════════════════════════
   LIEN "RÉFÉRENCE DE FACTURE" — cliquable pour télécharger le PDF
   ══════════════════════════════════════════════ */
.facture-link { color: var(--green); font-weight: 600; text-decoration: none; cursor: pointer; }
.facture-link:hover { text-decoration: underline; }


/* ══════════════════════════════════════════════
   SÉLECTEUR D'ASSO — Sidebar (visible si l'utilisateur a plusieurs assos)
   ══════════════════════════════════════════════ */
.asso-switcher {
  margin-top: 6px;
  width: 100%;
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--white);
  font-family: 'DM Sans', sans-serif;
  font-size: 12px;
  color: var(--text);
  cursor: pointer;
}
.asso-switcher:focus { outline: none; border-color: var(--green); }


/* ══════════════════════════════════════════════
   LISTE DE MATÉRIELS DANS LES MODALS (multi-matériels)
   Chaque ligne contient : select matériel + input quantité + bouton ×
   ══════════════════════════════════════════════ */
.materiels-list       { display: flex; flex-direction: column; gap: 6px; margin-bottom: 8px; }
.materiel-row         { display: grid; grid-template-columns: 1fr 80px 32px; gap: 6px; align-items: center; }
.materiel-row select,
.materiel-row input   { padding: 6px 8px; border: 1.5px solid var(--border); border-radius: 6px; font-family: 'DM Sans', sans-serif; font-size: 12px; background: var(--white); outline: none; }
.materiel-row select:focus,
.materiel-row input:focus { border-color: var(--green); }
.btn-remove-row       { background: transparent; border: 1px solid var(--border); border-radius: 6px; color: var(--text-muted); font-size: 16px; cursor: pointer; padding: 4px; line-height: 1; }
.btn-remove-row:hover { background: #fef2f2; border-color: var(--red); color: var(--red); }

.btn-add-materiel     { background: transparent; border: 1.5px dashed var(--border); border-radius: 6px; color: var(--text-muted); font-size: 12px; padding: 6px 10px; cursor: pointer; width: 100%; font-family: 'DM Sans', sans-serif; transition: all 0.15s; }
.btn-add-materiel:hover { border-color: var(--green); color: var(--green); background: var(--green-light); }


/* ══════════════════════════════════════════════
   BOUTONS EN CHARGEMENT — pendant qu'une requête est en cours
   Le helper withLoading() ajoute :disabled + change le texte en "Chargement…"
   ══════════════════════════════════════════════ */
.btn:disabled        { opacity: 0.6; cursor: wait; pointer-events: none; }


/* ══════════════════════════════════════════════
   BLOCS REPLIABLES — Vue admin sys de l'inventaire
   Chaque asso est dans un <details>. On clique sur le titre pour déplier/replier.
   ══════════════════════════════════════════════ */
.asso-block {
  background: var(--white);
  border-radius: 10px;
  margin-bottom: 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.04);
  overflow: hidden;
}
.asso-block > summary {
  list-style: none;          /* retire le triangle natif */
  cursor: pointer;
  padding: 14px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 500;
  user-select: none;
  transition: background 0.15s;
}
.asso-block > summary::-webkit-details-marker { display: none; }   /* Safari */
.asso-block > summary:hover { background: var(--green-light); }
.asso-block > summary::before {
  content: '▸';
  display: inline-block;
  margin-right: 10px;
  color: var(--green);
  transition: transform 0.15s;
}
.asso-block[open] > summary::before { transform: rotate(90deg); }
.asso-block .asso-name  { flex: 1; }
.asso-block table       { width: 100%; border-collapse: collapse; }
.asso-block th, .asso-block td { padding: 10px 18px; text-align: left; border-top: 1px solid var(--border); font-size: 13px; }
.asso-block th { background: var(--bg); font-weight: 600; color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
