/* ===== VARIABLES ===== */
:root {
  --principale: #0f766e;
  --principale-fonce: #115e59;
  --fond: #f1f5f4;
  --carte: #ffffff;
  --texte: #1f2937;
  --gris: #6b7280;
  --bordure: #dbe3e1;
  --succes: #15803d;
  --succes-fond: #dcfce7;
  --echec: #b91c1c;
  --echec-fond: #fee2e2;
  --alerte: #a16207;
  --alerte-fond: #fef3c7;
  --neutre-fond: #e5e7eb;
  --rayon: 10px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--fond);
  color: var(--texte);
  line-height: 1.5;
}

/* ===== EN-TÊTE ===== */
.entete {
  background: var(--principale);
  color: #fff;
  padding: 1.25rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
}
.entete h1 { font-size: 1.4rem; }
.entete p { opacity: 0.85; font-size: 0.9rem; }
.entete-droite { display: flex; align-items: center; gap: 0.75rem; font-size: 0.9rem; }

.badge-test {
  display: inline-block;
  background: #facc15;
  color: #422006;
  font-size: 0.7rem;
  font-weight: 700;
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  margin-left: 0.5rem;
  vertical-align: middle;
}

/* ===== MISE EN PAGE ===== */
.page { max-width: 1200px; margin: 1.5rem auto; padding: 0 1rem; display: grid; gap: 1.25rem; }
.page-etroite { max-width: 440px; margin: 3rem auto; padding: 0 1rem; }

.carte {
  background: var(--carte);
  border-radius: var(--rayon);
  padding: 1.25rem 1.5rem;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.06);
}
.carte h2 { font-size: 1.1rem; margin-bottom: 1rem; }
.carte h3 { font-size: 1rem; margin: 1.25rem 0 0.5rem; }
.carte p + p { margin-top: 0.5rem; }

.deux-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }

/* ===== INDICATEURS ===== */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 1rem; }
.kpi { background: var(--carte); border-radius: var(--rayon); padding: 1rem 1.25rem; box-shadow: 0 2px 10px rgba(0,0,0,.06); }
.kpi .libelle { color: var(--gris); font-size: 0.8rem; }
.kpi .valeur { font-size: 1.35rem; font-weight: 700; }
.kpi.alerte { border-left: 4px solid var(--alerte); }

.controles { list-style: none; display: grid; gap: 0.4rem; }
.controles li { font-size: 0.92rem; }

/* ===== FORMULAIRES ===== */
.champ { display: flex; flex-direction: column; margin-bottom: 1rem; }
.champ label { font-weight: 600; margin-bottom: 0.3rem; font-size: 0.9rem; }

input, select {
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--bordure);
  border-radius: 8px;
  font-size: 0.95rem;
  font-family: inherit;
  background: #fff;
}
input:focus, select:focus { outline: none; border-color: var(--principale); box-shadow: 0 0 0 3px rgba(15,118,110,.15); }

.filtres { display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center; margin-bottom: 1rem; }
.filtres input[type="search"] { flex: 1; min-width: 180px; }

/* ===== BOUTONS ===== */
button, .bouton {
  display: inline-block;
  padding: 0.6rem 1rem;
  border: none;
  border-radius: 8px;
  font-size: 0.92rem;
  font-weight: 600;
  cursor: pointer;
  background: var(--principale);
  color: #fff;
  text-decoration: none;
  font-family: inherit;
}
button:hover, .bouton:hover { background: var(--principale-fonce); }
button:disabled { opacity: 0.6; cursor: wait; }
button.pleine { width: 100%; padding: 0.8rem; }
button.secondaire, .bouton.secondaire { background: transparent; color: var(--principale); border: 1px solid var(--principale); }
button.secondaire:hover, .bouton.secondaire:hover { background: rgba(15,118,110,.08); }
button.danger { background: var(--echec); }
button.danger:hover { background: #991b1b; }
button.petit { padding: 0.3rem 0.7rem; font-size: 0.82rem; }
.entete button { background: transparent; border: 1px solid rgba(255,255,255,.7); padding: 0.35rem 0.8rem; }
.entete button:hover { background: rgba(255,255,255,.15); }

/* ===== MESSAGES ===== */
.message { margin-top: 1rem; padding: 0.7rem 1rem; border-radius: 8px; font-size: 0.92rem; }
.message.erreur { background: var(--echec-fond); color: var(--echec); }
.message.succes { background: var(--succes-fond); color: var(--succes); }
.cache { display: none !important; }

/* ===== TABLEAUX ===== */
.tableau-conteneur { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
th, td { padding: 0.55rem 0.5rem; text-align: left; border-bottom: 1px solid var(--bordure); white-space: nowrap; }
th { color: var(--gris); font-size: 0.75rem; text-transform: uppercase; }
td.nombre, th.nombre { text-align: right; }
td.vide { text-align: center; color: var(--gris); padding: 1.5rem; }
.mono { font-family: Consolas, "Courier New", monospace; font-size: 0.8rem; }
.actions { display: flex; gap: 0.4rem; }

/* ===== BADGES DE STATUT ===== */
.statut { display: inline-block; padding: 0.15rem 0.6rem; border-radius: 999px; font-size: 0.78rem; font-weight: 700; }
.statut.complete { background: var(--succes-fond); color: var(--succes); }
.statut.rejete { background: var(--echec-fond); color: var(--echec); }
.statut.en_verification { background: var(--alerte-fond); color: var(--alerte); }
.statut.annule, .statut.envoi_echoue { background: var(--neutre-fond); color: #374151; }

/* ===== DOCUMENTATION ===== */
pre {
  background: #0f172a;
  color: #e2e8f0;
  padding: 1rem;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.82rem;
  margin: 0.5rem 0 1rem;
}
code { font-family: Consolas, "Courier New", monospace; }
p code, td code, li code { background: var(--neutre-fond); padding: 0.05rem 0.35rem; border-radius: 4px; font-size: 0.85em; }
.doc ul { margin: 0.5rem 0 0.5rem 1.25rem; }


/* =====================================================
   RESPONSIVE : téléphone, tablette, ordinateur
   ===================================================== */

/* Base : cibles tactiles confortables et pas de zoom automatique sur iOS */
button, .bouton { min-height: 44px; }
button.petit { min-height: 36px; }
input, select { min-height: 44px; font-size: 16px; }
.actions { flex-wrap: wrap; }
.actions > input { flex: 1 1 140px; min-width: 0; }
.kpi .valeur { word-break: break-word; }

/* ----- Tablette (≤ 1024 px) : une seule colonne, tableaux défilants ----- */
@media (max-width: 1024px) {
  .deux-colonnes { grid-template-columns: 1fr; }
  .page { margin-top: 1rem; }
  .tableau-conteneur { -webkit-overflow-scrolling: touch; }
  th, td { padding: 0.6rem 0.45rem; }
}

/* ----- Téléphone (≤ 720 px) : tout s'empile, les tableaux deviennent des cartes ----- */
@media (max-width: 720px) {
  .entete { flex-direction: column; align-items: flex-start; padding: 1rem; }
  .entete h1 { font-size: 1.2rem; }
  .entete-droite { width: 100%; justify-content: space-between; flex-wrap: wrap; }

  .page { padding: 0 0.6rem; gap: 0.9rem; }
  .page-etroite { margin: 1.25rem auto; }
  .carte { padding: 1rem; }
  .kpis { grid-template-columns: 1fr 1fr; gap: 0.6rem; }
  .kpi { padding: 0.75rem 0.9rem; }
  .kpi .valeur { font-size: 1.1rem; }

  /* Formulaires : chaque élément sur toute la largeur */
  .filtres { flex-direction: column; align-items: stretch; }
  .filtres > * { width: 100%; }
  button.pleine { font-size: 1rem; }

  /* Tableaux → cartes : chaque ligne devient un bloc, chaque cellule une ligne "libellé : valeur" */
  .tableau-conteneur { overflow: visible; }
  table, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tr {
    border: 1px solid var(--bordure);
    border-radius: 8px;
    padding: 0.5rem 0.75rem;
    margin-bottom: 0.7rem;
    background: #fff;
  }
  td {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.75rem;
    padding: 0.4rem 0;
    border-bottom: 1px solid #f1f5f4;
    white-space: normal;
    text-align: right;
  }
  td:last-child { border-bottom: none; }
  td::before {
    content: attr(data-label);
    color: var(--gris);
    font-size: 0.75rem;
    text-transform: uppercase;
    text-align: left;
    flex: 0 0 38%;
  }
  td.nombre { text-align: right; }
  td.vide { display: block; text-align: center; }
  td.vide::before { content: none; }
  td .actions { justify-content: flex-end; width: 100%; }
  td .actions button { flex: 1 1 auto; }
}

/* ----- Très petit écran (≤ 380 px) ----- */
@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr; }
  td::before { flex-basis: 45%; }
}

/* Les cartes ne doivent jamais s'élargir à cause d'un tableau : c'est le tableau qui défile dedans */
.page > *, .deux-colonnes > *, .carte { min-width: 0; max-width: 100%; }
.tableau-conteneur { max-width: 100%; }
body { overflow-x: hidden; }

@media (max-width: 720px) {
  td { overflow-wrap: anywhere; min-width: 0; }
  td.mono { font-size: 0.75rem; }
}

/* Tablette : indiquer que le tableau se fait glisser horizontalement */
@media (min-width: 721px) and (max-width: 1024px) {
  .tableau-conteneur::before {
    content: '↔ Faites glisser le tableau pour voir toutes les colonnes';
    display: block;
    color: var(--gris);
    font-size: 0.78rem;
    margin-bottom: 0.4rem;
  }
}

.statut.paye { background: #dbeafe; color: #1e40af; }

/* Approvisionnement du float */
.floats { display: grid; gap: .6rem; }
.float-ligne { display: grid; grid-template-columns: 1fr 180px auto; gap: .6rem; align-items: center; padding: .6rem 0; border-bottom: 1px solid var(--bordure); }
.float-ligne:last-child { border-bottom: none; }
.float-infos { display: flex; flex-direction: column; }
.float-nom { color: var(--gris); font-size: .85rem; }
.float-infos strong { font-size: 1.15rem; }
@media (max-width: 720px) { .float-ligne { grid-template-columns: 1fr; } }

/* Création de partenaire */
.form-partenaire { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.form-partenaire button { grid-column: 1 / -1; }
.cles { margin-top: 1rem; padding: 1rem; border-radius: 8px; background: var(--alerte-fond); color: #713f12; font-size: .9rem; }
.cles label { display: block; font-weight: 600; margin-top: .6rem; }
.cle { display: flex; gap: .5rem; align-items: center; background: #fff; border-radius: 6px; padding: .4rem .5rem; margin: .25rem 0 .4rem; }
.cle code { flex: 1; font-size: .78rem; overflow-wrap: anywhere; color: var(--texte); }
#btn-fermer-cles { margin-top: .6rem; }
@media (max-width: 720px) { .form-partenaire { grid-template-columns: 1fr; } }
.form-partenaire > * { min-width: 0; width: 100%; }

/* Carte « Raccourci téléphone » */
.aide { margin: 0 0 .5rem; color: var(--gris); font-size: .9rem; }
.cles.neutre { background: var(--fond); color: var(--texte); margin-top: .5rem; }
.cle button { flex-shrink: 0; }

/* Rôles et comptes du back-office */
body.role-operateur .admin-seul { display: none !important; }
.role-badge { display: inline-block; font-size: .7rem; padding: .1rem .45rem; border-radius: 999px; background: rgba(255,255,255,.2); text-transform: uppercase; letter-spacing: .03em; }
.secondaire-clair { background: transparent; border: 1px solid rgba(255,255,255,.6); color: #fff; }
.form-compte { display: grid; grid-template-columns: 2fr 1fr auto; gap: .5rem; margin-top: .75rem; }
.form-compte > * { min-width: 0; }
@media (max-width: 720px) { .form-compte { grid-template-columns: 1fr; } }
.dialogue { border: none; border-radius: var(--rayon); padding: 1.25rem; width: min(420px, 92vw); box-shadow: 0 10px 40px rgba(0,0,0,.25); }
.dialogue::backdrop { background: rgba(15,23,42,.5); }
.dialogue label { display: block; font-weight: 600; font-size: .9rem; margin: .7rem 0 .25rem; }
.dialogue input { width: 100%; }
.dialogue-actions { display: flex; justify-content: flex-end; gap: .5rem; margin-top: 1rem; }

/* Double authentification */
.qr-2fa { display: block; width: 200px; height: 200px; margin: .5rem auto; background: #fff; border: 1px solid var(--bordure); border-radius: 8px; padding: .25rem; }
.champ-code { font-size: 1.4rem; letter-spacing: .3em; text-align: center; font-variant-numeric: tabular-nums; }
.codes-secours { white-space: pre; line-height: 1.7; font-size: .95rem; }
