/* Sportezvousbien : feuille unique.
   Deux familles de jetons : structure et notions métier.
   Une notion garde la même couleur partout : pastille, badge, chiffre, tableau. */

/* ---------------------------------------------------------------- jetons */

:root, [data-theme=light] {
  --fond:          #eceff1;
  --fond-carte:    #ffffff;
  --fond-eleve:    #f6f8f9;
  --fond-doux:     #e3e8ea;
  --encre:         #14303d;
  --encre-douce:   #47606c;
  --encre-tenue:   #7b8f99;
  --bordure:       #ccd6da;
  --bordure-douce: #e0e7ea;
  --accent:        #0d6e78;
  --accent-doux:   #d7ebed;
  --accent-fort:   #095057;
  --barre-fond:    #14303d;
  --barre-texte:   #f2f7f8;
  --barre-tenue:   #9db7c0;
  --barre-survol:  rgba(255, 255, 255, .12);

  --brouillon:      #6b7a83;
  --brouillon-doux: #e6eaec;
  --devis:          #3f6ca8;
  --devis-doux:     #dfe8f4;
  --facture:        #0d6e78;
  --facture-doux:   #d7ebed;
  --avoir:          #85539c;
  --avoir-doux:     #ece0f2;
  --annule:         #8c9499;
  --annule-doux:    #e9ecee;
  --regle:          #2c7a51;
  --regle-doux:     #dcefe4;
  --acompte:        #b3830f;
  --acompte-doux:   #f6ebd3;
  --retard:         #ad3427;
  --retard-doux:    #f7dedb;
  --encadrant:      #4f6570;
  --encadrant-doux: #e4e9eb;
  --mineur:         #a2571c;
  --mineur-doux:    #f6e5d7;
  --cout:           #8a6a3f;
  --cout-doux:      #f1e8dc;
  --marge:          #1f6f8b;
  --marge-doux:     #dcecf2;

  --rayon:    6px;
  --rayon-lg: 12px;
  --ombre:    0 1px 2px rgba(20, 48, 61, .07), 0 4px 14px rgba(20, 48, 61, .05);
}

:root[data-theme=dark] {
  --fond:          #101d24;
  --fond-carte:    #16272f;
  --fond-eleve:    #1d323b;
  --fond-doux:     #223a44;
  --encre:         #e6eef1;
  --encre-douce:   #a8bcc4;
  --encre-tenue:   #7b939d;
  --bordure:       #2b4450;
  --bordure-douce: #223842;
  --accent:        #3fb3bd;
  --accent-doux:   #123c42;
  --accent-fort:   #6fd3db;
  --barre-fond:    #0a171d;
  --barre-texte:   #e6eef1;
  --barre-tenue:   #8ba6b1;
  --barre-survol:  rgba(255, 255, 255, .1);

  --brouillon:      #93a5ae;  --brouillon-doux: #26363e;
  --devis:          #7ba5da;  --devis-doux:     #1b2f45;
  --facture:        #3fb3bd;  --facture-doux:   #123c42;
  --avoir:          #b98ecd;  --avoir-doux:     #33223c;
  --annule:         #8c9499;  --annule-doux:    #262f33;
  --regle:          #5fbc8a;  --regle-doux:     #14352a;
  --acompte:        #dfae4b;  --acompte-doux:   #3a2f14;
  --retard:         #e5776a;  --retard-doux:    #42201d;
  --encadrant:      #90a6b0;  --encadrant-doux: #223138;
  --mineur:         #d99a5f;  --mineur-doux:    #3c2a1a;
  --cout:           #c9a56f;  --cout-doux:      #362b1c;
  --marge:          #6bb6d1;  --marge-doux:     #17323d;

  --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme=light]):not([data-theme=dark]) {
    --fond:          #101d24;
    --fond-carte:    #16272f;
    --fond-eleve:    #1d323b;
    --fond-doux:     #223a44;
    --encre:         #e6eef1;
    --encre-douce:   #a8bcc4;
    --encre-tenue:   #7b939d;
    --bordure:       #2b4450;
    --bordure-douce: #223842;
    --accent:        #3fb3bd;
    --accent-doux:   #123c42;
    --accent-fort:   #6fd3db;
    --barre-fond:    #0a171d;
    --barre-texte:   #e6eef1;
    --barre-tenue:   #8ba6b1;
    --barre-survol:  rgba(255, 255, 255, .1);

    --brouillon:      #93a5ae;  --brouillon-doux: #26363e;
    --devis:          #7ba5da;  --devis-doux:     #1b2f45;
    --facture:        #3fb3bd;  --facture-doux:   #123c42;
    --avoir:          #b98ecd;  --avoir-doux:     #33223c;
    --annule:         #8c9499;  --annule-doux:    #262f33;
    --regle:          #5fbc8a;  --regle-doux:     #14352a;
    --acompte:        #dfae4b;  --acompte-doux:   #3a2f14;
    --retard:         #e5776a;  --retard-doux:    #42201d;
    --encadrant:      #90a6b0;  --encadrant-doux: #223138;
    --mineur:         #d99a5f;  --mineur-doux:    #3c2a1a;
    --cout:           #c9a56f;  --cout-doux:      #362b1c;
    --marge:          #6bb6d1;  --marge-doux:     #17323d;

    --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 14px rgba(0, 0, 0, .25);
  }
}

/* --------------------------------------------------------------- socle */

*, *::before, *::after { box-sizing: border-box; }

/* L'attribut hidden doit primer sur toute règle display de cette feuille. */
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--fond);
  color: var(--encre);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  font-variant-numeric: tabular-nums;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.015em; }
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 0.98rem; font-weight: 600; }
p  { margin: 0 0 .6em; max-width: 68ch; }

/* Un bloc de texte centré doit l'être aussi comme boîte, pas seulement dans son
   contenu : sans cela la limite de 68ch le laisse calé à gauche. */
[style*="text-align: center"] p,
.texte-centre p { margin-inline: auto; }

a { color: var(--accent); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: 3px;
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}

/* ------------------------------------------------------------- controles */

button, input, select, textarea {
  font: inherit;
  color: inherit;
  font-variant-numeric: inherit;
}

.bouton {
  display: inline-flex;
  align-items: center;
  gap: .4em;
  padding: .5em 1em;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--fond-carte);
  color: var(--encre);
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease;
}
.bouton:hover { background: var(--fond-eleve); }
.bouton:disabled { opacity: .5; cursor: not-allowed; }

.bouton.principal {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 500;
}
.bouton.principal:hover { background: var(--accent-fort); border-color: var(--accent-fort); }

.bouton.danger { color: var(--retard); border-color: var(--retard); background: var(--retard-doux); }

.bouton-icone {
  width: 2.1rem; height: 2.1rem;
  display: grid; place-items: center;
  border: 1px solid transparent;
  border-radius: var(--rayon);
  background: transparent;
  color: var(--encre-douce);
  cursor: pointer;
  font-size: .95rem;
}
.bouton-icone:hover { background: var(--fond-doux); color: var(--encre); }

label { display: block; font-size: .82rem; color: var(--encre-douce); margin-bottom: .25em; }

input, select, textarea {
  width: 100%;
  padding: .5em .65em;
  border: 1px solid var(--bordure);
  border-radius: var(--rayon);
  background: var(--fond-carte);
}
input:disabled, select:disabled { background: var(--fond-doux); color: var(--encre-tenue); }

.champ { margin-bottom: .85rem; }
.champs { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 0 .85rem; }
.aide { font-size: .8rem; color: var(--encre-tenue); margin-top: .3em; }

/* ---------------------------------------------------------- barre haute */

.barre {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem;
  padding: .55rem clamp(.8rem, 3vw, 1.5rem);
  background: var(--barre-fond);
  color: var(--barre-texte);
  padding-top: max(.55rem, env(safe-area-inset-top));
}
.barre-marque { font-weight: 600; letter-spacing: .01em; }
.barre-role { margin-left: .6rem; font-size: .8rem; color: var(--barre-tenue); }
.barre-actions { display: flex; gap: .15rem; }
.barre .bouton-icone { color: var(--barre-tenue); }
.barre .bouton-icone:hover { background: var(--barre-survol); color: var(--barre-texte); }

/* ------------------------------------------------------------- onglets */

.onglets {
  position: sticky; top: 3.1rem; z-index: 25;
  display: flex; gap: .15rem;
  padding: 0 clamp(.8rem, 3vw, 1.5rem);
  background: var(--fond-carte);
  border-bottom: 1px solid var(--bordure);
  overflow-x: auto;
  scrollbar-width: none;
}
.onglets::-webkit-scrollbar { display: none; }
.onglets button {
  flex: 0 0 auto;
  padding: .8rem .75rem;
  border: 0;
  border-bottom: 2px solid transparent;
  background: transparent;
  color: var(--encre-douce);
  cursor: pointer;
  white-space: nowrap;
}
.onglets button:hover { color: var(--encre); }
.onglets button.actif { color: var(--accent); border-bottom-color: var(--accent); font-weight: 500; }
.onglets button[hidden] { display: none; }

@media (max-width: 720px) { .onglets { display: none; } }

/* -------------------------------------------------------- filtre global */

.filtre {
  display: flex; align-items: center; gap: .6rem; flex-wrap: wrap;
  padding: .6rem clamp(.8rem, 3vw, 1.5rem);
  background: var(--fond-eleve);
  border-bottom: 1px solid var(--bordure-douce);
}
.filtre select { width: auto; min-width: 14rem; }
.filtre .repere { font-size: .82rem; color: var(--encre-douce); }

/* ------------------------------------------------------------ panneaux */

.contenu {
  padding: clamp(.9rem, 3vw, 1.6rem);
  padding-bottom: 6rem;
  max-width: 1180px;
  margin: 0 auto;
}
.panneau { display: none; }
.panneau.actif { display: block; }

.carte {
  background: var(--fond-carte);
  border: 1px solid var(--bordure-douce);
  border-radius: var(--rayon-lg);
  box-shadow: var(--ombre);
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.carte-tete {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: .8rem; flex-wrap: wrap;
  margin-bottom: .8rem;
}

.grille { display: grid; gap: 1rem; }
@media (min-width: 860px) {
  .grille.deux { grid-template-columns: 1fr 1fr; }
  .grille.trois { grid-template-columns: repeat(3, 1fr); }
}

/* ------------------------------------------------------------- chiffres */

.chiffres { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: .8rem; }
.chiffre { padding: .7rem .8rem; background: var(--fond-eleve); border-radius: var(--rayon); }
.chiffre .valeur { font-size: 1.35rem; font-weight: 600; letter-spacing: -.02em; }
.chiffre .intitule { font-size: .8rem; color: var(--encre-douce); }
.chiffre.regle   .valeur { color: var(--regle); }
.chiffre.acompte .valeur { color: var(--acompte); }
.chiffre.retard  .valeur { color: var(--retard); }
.chiffre.cout    .valeur { color: var(--cout); }
.chiffre.marge   .valeur { color: var(--marge); }

/* ---------------------------------------------------- jauge de couchages */

.couchages { display: flex; flex-wrap: wrap; gap: 4px; margin: .2rem 0 .7rem; }
.couchage {
  width: 15px; height: 22px;
  border-radius: 3px 3px 2px 2px;
  background: var(--fond-doux);
  border: 1px solid var(--bordure);
}
.couchage.occupe    { background: var(--accent); border-color: var(--accent); }
.couchage.encadrant { background: var(--encadrant); border-color: var(--encadrant); }
.couchage.mineur    { background: var(--mineur); border-color: var(--mineur); }
.couchages-legende { display: flex; flex-wrap: wrap; gap: .9rem; font-size: .8rem; color: var(--encre-douce); }

/* -------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: .35em;
  padding: .15em .6em;
  border-radius: 999px;
  font-size: .78rem;
  border: 1px solid transparent;
  white-space: nowrap;
}
.badge .pastille { width: .5em; height: .5em; border-radius: 50%; background: currentColor; }

.badge.brouillon { color: var(--brouillon); background: var(--brouillon-doux); border-color: var(--brouillon); }
.badge.devis     { color: var(--devis);     background: var(--devis-doux);     border-color: var(--devis); }
.badge.facture   { color: var(--facture);   background: var(--facture-doux);   border-color: var(--facture); }
.badge.avoir     { color: var(--avoir);     background: var(--avoir-doux);     border-color: var(--avoir); }
.badge.annule    { color: var(--annule);    background: var(--annule-doux);    border-color: var(--annule); }
.badge.regle     { color: var(--regle);     background: var(--regle-doux);     border-color: var(--regle); }
.badge.acompte   { color: var(--acompte);   background: var(--acompte-doux);   border-color: var(--acompte); }
.badge.retard    { color: var(--retard);    background: var(--retard-doux);    border-color: var(--retard); }
.badge.encadrant { color: var(--encadrant); background: var(--encadrant-doux); border-color: var(--encadrant); }
.badge.mineur    { color: var(--mineur);    background: var(--mineur-doux);    border-color: var(--mineur); }
.badge.cout      { color: var(--cout);      background: var(--cout-doux);      border-color: var(--cout); }
.badge.marge     { color: var(--marge);     background: var(--marge-doux);     border-color: var(--marge); }

/* Barre d'équilibre : ce que la marge finance face aux dépenses engagées. */
.equilibre { margin: .4rem 0 .8rem; }
.equilibre-piste {
  position: relative;
  height: 14px;
  border-radius: 7px;
  background: var(--marge-doux);
  border: 1px solid var(--bordure);
  overflow: hidden;
}
.equilibre-part { position: absolute; top: 0; bottom: 0; left: 0; }
.equilibre-part.depenses { background: var(--cout); }
.equilibre-repere {
  position: absolute; top: -3px; bottom: -3px; width: 2px;
  background: var(--encre);
}
.equilibre-legende {
  display: flex; justify-content: space-between; flex-wrap: wrap; gap: .6rem;
  font-size: .8rem; color: var(--encre-douce); margin-top: .35rem;
}

/* ------------------------------------------------------------- tableaux */

.tableau-cadre { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { padding: .55rem .6rem; text-align: left; border-bottom: 1px solid var(--bordure-douce); vertical-align: top; }
th { font-weight: 600; color: var(--encre-douce); font-size: .82rem; }
td.nombre, th.nombre { text-align: right; white-space: nowrap; }
tbody tr:hover { background: var(--fond-eleve); }
tr.groupe-chambre td { background: var(--fond-doux); font-weight: 500; }
.total-ligne td { border-top: 2px solid var(--bordure); font-weight: 600; border-bottom: 0; }

/* --------------------------------------------------- écran de démarrage */

.accueil-premier { padding: 1.6rem 1.5rem 1.2rem; }
.accueil-premier h1 { font-size: 1.7rem; }
.accueil-intro { color: var(--encre-douce); margin: .4rem 0 1.4rem; font-size: 1.02rem; }

.etapes { list-style: none; margin: 0; padding: 0; }

.etape {
  display: grid;
  grid-template-columns: 2rem 1fr;
  gap: .9rem;
  padding: 1rem 0;
  border-top: 1px solid var(--bordure-douce);
}
.etape:first-child { border-top: 0; padding-top: 0; }

.etape-rang {
  width: 2rem; height: 2rem;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--fond-doux);
  color: var(--encre-douce);
  font-size: .9rem; font-weight: 600;
}
.etape.courante .etape-rang { background: var(--accent); color: #fff; }
.etape.faite .etape-rang { background: var(--regle-doux); color: var(--regle); border: 1px solid var(--regle); }

.etape-corps h3 { margin-bottom: .2rem; }
.etape-corps p { color: var(--encre-douce); margin-bottom: .6rem; font-size: .92rem; }
.etape.faite .etape-corps h3,
.etape.faite .etape-corps p { color: var(--encre-tenue); }

.etape-etat {
  display: inline-block;
  font-size: .8rem;
  color: var(--regle);
}

.reperes { display: grid; gap: 1.1rem; }
@media (min-width: 780px) { .reperes { grid-template-columns: 1fr 1fr; gap: 1.1rem 2rem; } }
.reperes h3 { margin-bottom: .2rem; }
.reperes p { color: var(--encre-douce); font-size: .9rem; margin: 0; }

/* -------------------------------------------------------------- divers */

.vide {
  padding: 2rem 1rem;
  text-align: center;
  color: var(--encre-douce);
  background: var(--fond-eleve);
  border-radius: var(--rayon-lg);
}
.vide h3 { margin-bottom: .35rem; color: var(--encre); }
.vide p { margin-inline: auto; }
.vide .bouton { margin-top: .8rem; }

.anomalies { background: var(--retard-doux); border: 1px solid var(--retard); border-radius: var(--rayon); padding: .7rem .9rem; }
.anomalies h3 { color: var(--retard); margin-bottom: .35rem; }
.anomalies ul { margin: 0; padding-left: 1.1rem; }
.anomalies li { margin-bottom: .2rem; }
.anomalies li.avertissement { color: var(--acompte); }

.barre-outils { display: flex; gap: .5rem; flex-wrap: wrap; margin-bottom: .8rem; }
.pousse { margin-left: auto; }

/* --------------------------------------------------------------- pied */

.pied {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: flex; align-items: center; gap: 1rem;
  padding: .4rem clamp(.8rem, 3vw, 1.5rem);
  background: var(--fond-carte);
  border-top: 1px solid var(--bordure);
  font-size: .78rem;
  color: var(--encre-douce);
}
.pied .etat { margin-left: auto; display: flex; align-items: center; gap: .4rem; }
.pied .pastille { width: .55em; height: .55em; border-radius: 50%; background: var(--regle); display: inline-block; }
.pied .etat.hors-ligne .pastille { background: var(--retard); }
.pied .etat.attente .pastille { background: var(--acompte); }

@media (max-width: 720px) {
  .pied { bottom: 3.6rem; padding-bottom: .4rem; }
  #pied-identite { display: none; }
}

/* ------------------------------------------------------ navigation basse */

.navigation-basse { display: none; }

@media (max-width: 720px) {
  .navigation-basse {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 25;
    display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
    background: var(--fond-carte);
    border-top: 1px solid var(--bordure);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .navigation-basse button {
    padding: .55rem .2rem;
    border: 0; background: transparent;
    color: var(--encre-douce);
    font-size: .72rem;
    cursor: pointer;
    border-top: 2px solid transparent;
  }
  .navigation-basse button.actif { color: var(--accent); border-top-color: var(--accent); }
  .contenu { padding-bottom: 9rem; }
}

/* ------------------------------------------------------------- modales */

.modale-fond {
  position: fixed; inset: 0; z-index: 60;
  display: none;
  align-items: center; justify-content: center;
  padding: 1rem;
  background: rgba(10, 25, 32, .55);
}
.modale-fond.visible { display: flex; }
.modale {
  width: min(680px, 100%);
  max-height: 88dvh;
  display: flex; flex-direction: column;
  background: var(--fond-carte);
  border-radius: var(--rayon-lg);
  box-shadow: 0 20px 50px rgba(0, 0, 0, .3);
}
.modale-tete {
  display: flex; align-items: center; justify-content: space-between;
  padding: .8rem 1rem; border-bottom: 1px solid var(--bordure-douce);
}
.modale-corps { padding: 1rem; overflow-y: auto; }
.modale-pied {
  display: flex; gap: .5rem; justify-content: flex-end;
  padding: .8rem 1rem; border-top: 1px solid var(--bordure-douce);
}

/* ------------------------------------------------------------ messages */

.messages {
  position: fixed; z-index: 80;
  left: 50%; transform: translateX(-50%);
  bottom: 4.5rem;
  display: flex; flex-direction: column; gap: .4rem;
  width: min(520px, calc(100% - 2rem));
}
.message {
  padding: .6rem .9rem;
  border-radius: var(--rayon);
  background: var(--barre-fond);
  color: var(--barre-texte);
  box-shadow: var(--ombre);
}
.message.erreur { background: var(--retard); color: #fff; }
.message.succes { background: var(--regle); color: #fff; }

/* ----------------------------------------------------------- connexion */

.connexion {
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: 1.2rem;
  background:
    radial-gradient(1100px 520px at 50% -10%, var(--accent-doux), transparent 65%),
    var(--fond);
}
.connexion-carte {
  width: min(420px, 100%);
  background: var(--fond-carte);
  border: 1px solid var(--bordure-douce);
  border-radius: var(--rayon-lg);
  box-shadow: var(--ombre);
  padding: 1.6rem 1.5rem;
}
.connexion-titre { font-size: 1.45rem; }
.connexion-sous-titre { color: var(--encre-douce); font-size: .9rem; margin-bottom: 1.3rem; }
.connexion p { max-width: none; }
.connexion .bouton { width: 100%; justify-content: center; margin-top: .4rem; }

/* -------------------------------------------------------------- impression */

@media print {
  .barre, .onglets, .filtre, .navigation-basse, .pied, .barre-outils { display: none !important; }
  .carte { box-shadow: none; border: 0; }
  body { background: #fff; }
}
