/* gestPlomberie - feuille de style. Palette validee (contraste, daltonisme) pour les graphiques. */

:root {
  --bleu: #2a78d6;
  --bleu-fonce: #1c5cab;
  --bleu-clair: #e8f0fb;
  --orange: #eb6834;
  --encre: #0b0b0b;
  --encre-2: #52514e;
  --sourd: #898781;
  --trait: #e1e0d9;
  --bord: rgba(11, 11, 11, .10);
  --fond: #f4f5f7;
  --surface: #ffffff;
  --ok: #006300;
  --ok-fond: #e6f4e6;
  --danger: #d03b3b;
  --danger-fond: #fbe9e9;
  --avert: #8a5a00;
  --avert-fond: #fff4d6;
  --lateral: #0f172a;
  --lateral-texte: #cbd5e1;
  --rayon: 12px;
  --ombre: 0 1px 2px rgba(11, 11, 11, .04), 0 4px 16px rgba(11, 11, 11, .05);
  --largeur-lateral: 240px;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--encre);
  background: var(--fond);
  min-height: 100vh;
}
a { color: var(--bleu); }
h1, h2, h3 { line-height: 1.25; letter-spacing: -.01em; }
.icone { flex: none; vertical-align: -0.2em; }

/* --- Structure : menu lateral + contenu ------------------------------------- */
body.connecte { display: flex; }
.lateral {
  display: none; flex-direction: column; gap: 1rem;
  width: var(--largeur-lateral); min-height: 100vh; padding: 1.1rem .9rem;
  background: var(--lateral); color: var(--lateral-texte);
  position: sticky; top: 0; align-self: flex-start; height: 100vh;
}
body.connecte .lateral { display: flex; }
.cadre { flex: 1; min-width: 0; }
.entete-mobile { display: none; }

.marque {
  display: inline-flex; align-items: center; gap: .55rem; text-decoration: none; color: inherit;
  font-weight: 700; font-size: 1.15rem; letter-spacing: -.01em;
}
.marque .pastille {
  display: inline-grid; place-items: center; width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #3987e5, #1c5cab); color: #fff;
}
.marque b { color: #fff; font-weight: 800; }
.marque span { color: var(--lateral-texte); font-weight: 500; }

.entreprise {
  display: flex; align-items: center; gap: .7rem; padding: .7rem .75rem;
  border-radius: 10px; background: rgba(255, 255, 255, .06);
}
.entreprise .logo {
  width: 44px; height: 44px; border-radius: 8px; background: #fff; object-fit: contain; padding: 3px; flex: none;
}
.entreprise .initiales {
  width: 44px; height: 44px; border-radius: 8px; display: grid; place-items: center; flex: none;
  background: var(--bleu); color: #fff; font-weight: 700; font-size: 1rem;
}
.entreprise .corps {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}
.entreprise .nom { font-weight: 600; color: #fff; font-size: .92rem; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.entreprise .role {
    font-size: .78rem;
    color: var(--lateral-texte);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#menu { display: flex; flex-direction: column; gap: .15rem; }
#menu a {
  display: flex; align-items: center; gap: .75rem; padding: .65rem .8rem; border-radius: 10px;
  color: var(--lateral-texte); text-decoration: none; font-weight: 500; transition: background .15s;
}
#menu a:hover { background: rgba(255, 255, 255, .07); color: #fff; }
#menu a.actif { background: rgba(57, 135, 229, .22); color: #fff; }
#menu a.actif .icone { color: #7db3f0; }
.lateral-pied { margin-top: auto; }
.lien {
  display: inline-flex; align-items: center; gap: .6rem; background: none; border: 0; font: inherit;
  cursor: pointer; color: var(--lateral-texte); padding: .6rem .8rem; border-radius: 10px; width: 100%;
}
.lien:hover { background: rgba(255, 255, 255, .07); color: #fff; }

#app { max-width: 1180px; margin: 0 auto; padding: 1.5rem 2rem 3rem; }
body:not(.connecte) #app { max-width: none; padding: 0; }

/* --- En-tetes et cartes --------------------------------------------------- */
.titre { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: .75rem 1rem; margin: 0 0 1.25rem; }
.titre h1 { margin: 0; font-size: 1.6rem; font-weight: 700; }
.titre .sur-titre { display: block; font-size: .85rem; font-weight: 500; color: var(--sourd); margin-bottom: .15rem; }
.titre .sur-titre::first-letter { text-transform: uppercase; }
.actions, .barre-actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.barre-actions { margin: 1rem 0; }
.sous-titre { margin: -.9rem 0 1.25rem; color: var(--encre-2); }
.carte {
  background: var(--surface); border: 1px solid var(--bord); border-radius: var(--rayon);
  padding: 1.15rem 1.25rem; margin-bottom: 1rem; box-shadow: var(--ombre);
}
.carte h2 { margin: 0 0 .85rem; font-size: 1.02rem; font-weight: 650; display: flex; align-items: center; gap: .5rem; }
.carte h2 .compteur { font-weight: 500; color: var(--sourd); font-size: .9rem; }
.carte h2 .voir-tout { margin-left: auto; font-size: .85rem; font-weight: 500; text-decoration: none; }
h3 { font-size: .95rem; margin: .5rem 0; }
.vide, .chargement, .discret { color: var(--sourd); margin: .25rem 0; }
.pre { white-space: pre-line; }
.alerte {
  display: flex; gap: .7rem; align-items: flex-start; background: var(--avert-fond); color: var(--avert);
  border: 1px solid #f3dca0; padding: .8rem 1rem; border-radius: 10px; margin-bottom: 1rem;
}
.alerte a { color: inherit; font-weight: 600; }
.alerte .icone { margin-top: .1rem; }
.zone-danger { margin: 2rem 0 1rem; text-align: right; }

/* --- Formulaires -------------------------------------------------------------- */
.grille { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: .85rem 1rem; }
.grille label { display: flex; flex-direction: column; gap: .3rem; font-size: .84rem; font-weight: 500; color: var(--encre-2); }
.grille label.large { grid-column: 1 / -1; }
.grille label.case { flex-direction: row; align-items: center; gap: .6rem; color: var(--encre); font-weight: 500; }
input, select, textarea {
  font: inherit; color: var(--encre); padding: .6rem .75rem; border: 1px solid #cfd2d8;
  border-radius: 9px; background: #fff; width: 100%; min-height: 44px;
}
input[type="checkbox"] { width: 22px; height: 22px; min-height: 0; accent-color: var(--bleu); }
textarea { resize: vertical; min-height: 0; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--bleu); outline-offset: -1px; border-color: var(--bleu); }
form .actions { margin-top: 1rem; }

button, .bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: .45rem;
  font: inherit; font-weight: 550; padding: .6rem 1rem; min-height: 44px; border-radius: 9px; cursor: pointer;
  border: 1px solid #cfd2d8; background: #fff; color: var(--encre); text-decoration: none; white-space: nowrap;
  transition: background .15s, border-color .15s;
}
button:hover, .bouton:hover { border-color: var(--bleu); background: var(--bleu-clair); }
button:disabled { opacity: .5; cursor: wait; }
.principal { background: var(--bleu); border-color: var(--bleu); color: #fff; }
.principal:hover { background: var(--bleu-fonce); border-color: var(--bleu-fonce); }
.danger { color: var(--danger); border-color: #f0b4b4; }
.danger:hover { background: var(--danger-fond); border-color: var(--danger); }
.grand { font-size: 1.05rem; padding: .75rem 1.4rem; }
button.petit { min-height: 36px; padding: .25rem .6rem; }
.recherche { margin-bottom: .75rem; }

/* --- Tableaux et listes ------------------------------------------------------- */
.defile { overflow-x: auto; margin: 0 -.25rem; padding: 0 .25rem; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: .6rem .55rem; text-align: left; border-bottom: 1px solid #eceef1; vertical-align: top; }
th { font-size: .78rem; color: var(--sourd); font-weight: 600; text-transform: uppercase; letter-spacing: .03em; }
tbody tr:last-child td { border-bottom: 0; }
.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tr.cliquable { cursor: pointer; }
tr.cliquable:hover { background: var(--bleu-clair); }
.retard { color: var(--danger); font-weight: 600; }
table.lignes td { padding: .35rem .3rem; }
table.lignes textarea { min-width: 220px; }
table.lignes .qte { width: 90px; }
table.lignes .prix { width: 110px; }
table.lignes .unite { width: 90px; }
table.lignes select { width: 90px; }
td.designation { white-space: pre-line; }

.liste-lignes { display: flex; flex-direction: column; }
.ligne-liste {
  display: flex; align-items: center; gap: .9rem; padding: .7rem .4rem; border-bottom: 1px solid #eceef1;
  text-decoration: none; color: inherit; border-radius: 8px;
}
.ligne-liste:last-child { border-bottom: 0; }
.ligne-liste:hover { background: var(--bleu-clair); }
.ligne-liste .puce {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center; flex: none;
  background: var(--bleu-clair); color: var(--bleu-fonce);
}
.ligne-liste .puce.danger { background: var(--danger-fond); color: var(--danger); }
.ligne-liste .puce.ok { background: var(--ok-fond); color: var(--ok); }
.ligne-liste .puce.neutre { background: #eef0f3; color: var(--encre-2); }
.ligne-liste .corps { flex: 1; min-width: 0; }
.ligne-liste .principal-texte { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.ligne-liste .second { font-size: .84rem; color: var(--sourd); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; display: block; }
.ligne-liste .droite { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ligne-liste .droite strong { display: block; font-weight: 650; }
.ligne-liste .droite .second { font-size: .8rem; }

.badge { display: inline-flex; align-items: center; gap: .3rem; padding: .18rem .6rem; border-radius: 999px; font-size: .78rem; font-weight: 600; background: #eef0f3; color: var(--encre-2); }
.badge.emise, .badge.accepte { background: var(--ok-fond); color: var(--ok); }
.badge.envoye { background: var(--bleu-clair); color: var(--bleu-fonce); }
.badge.brouillon { background: var(--avert-fond); color: var(--avert); }
.badge.refuse, .badge.annule, .badge.retard { background: var(--danger-fond); color: var(--danger); }

.onglets { display: inline-flex; gap: .25rem; margin-bottom: 1rem; flex-wrap: wrap; background: #e9ebef; padding: .25rem; border-radius: 10px; }
.onglets a { padding: .45rem .95rem; border-radius: 8px; text-decoration: none; color: var(--encre-2); font-weight: 500; }
.onglets a.actif { background: #fff; color: var(--encre); box-shadow: 0 1px 3px rgba(11, 11, 11, .12); }

/* --- Tableau de bord ---------------------------------------------------------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(210px, 1fr)); gap: 1rem; margin-bottom: 1rem; }
.kpi { margin: 0; display: flex; flex-direction: column; gap: .25rem; }
.kpi .etiquette { font-size: .84rem; color: var(--encre-2); font-weight: 500; display: flex; align-items: center; gap: .45rem; }
.kpi .valeur { font-size: 1.75rem; font-weight: 700; letter-spacing: -.02em; line-height: 1.15; }
.kpi.hero .valeur { font-size: 2.6rem; }
.kpi .detail { font-size: .84rem; color: var(--sourd); display: flex; align-items: center; gap: .35rem; flex-wrap: wrap; }
.kpi.hero { background: linear-gradient(135deg, #1c5cab, #2a78d6); color: #fff; border: 0; }
.kpi.hero .etiquette, .kpi.hero .detail { color: rgba(255, 255, 255, .85); }
.kpi.hero .detail.retard { color: #ffd1d1; font-weight: 600; }
.delta { display: inline-flex; align-items: center; gap: .15rem; font-weight: 600; }
.delta.haut { color: var(--ok); }
.delta.bas { color: var(--danger); }
.kpi.hero .delta.haut { color: #bdf5bd; }
.kpi.hero .delta.bas { color: #ffd1d1; }

.deux-colonnes { display: grid; grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); gap: 1rem; align-items: start; }
.deux-colonnes > .carte { margin-bottom: 0; }
.deux-colonnes .pile { display: flex; flex-direction: column; gap: 1rem; }
.listes { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 1rem; margin-top: 1rem; }
.listes .carte { margin-bottom: 0; }

.graphique { position: relative; }
.graphique svg { width: 100%; height: auto; display: block; }
.graphique .grille-h { stroke: var(--trait); stroke-width: 1; }
.graphique .axe { stroke: #c3c2b7; stroke-width: 1; }
.graphique text { font-size: 11px; fill: var(--sourd); }
.graphique text.direct { fill: var(--encre-2); font-weight: 600; }
.graphique .zone { fill: transparent; cursor: default; }
.graphique .zone:hover { fill: rgba(11, 11, 11, .035); }
.graphique .barre { transition: opacity .12s; }
.legende { display: flex; flex-wrap: wrap; gap: .4rem 1.1rem; font-size: .84rem; color: var(--encre-2); margin: -.3rem 0 .6rem; }
.legende span { display: inline-flex; align-items: center; gap: .4rem; }
.legende i { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.infobulle {
  position: absolute; pointer-events: none; background: var(--encre); color: #fff; padding: .45rem .65rem;
  border-radius: 8px; font-size: .82rem; line-height: 1.4; white-space: nowrap; transform: translate(-50%, -100%);
  box-shadow: 0 4px 14px rgba(0, 0, 0, .2); display: none; z-index: 5;
}
.infobulle.visible { display: block; }
.infobulle b { font-weight: 600; }
.infobulle .cle { display: inline-flex; align-items: center; gap: .35rem; color: #d7d7d7; }
.infobulle i { width: 8px; height: 8px; border-radius: 2px; display: inline-block; }
details.tableau-donnees { margin-top: .5rem; }
details.tableau-donnees summary { cursor: pointer; color: var(--bleu); font-size: .85rem; font-weight: 500; padding: .3rem 0; }

.barres-h { display: flex; flex-direction: column; gap: .6rem; }
.barres-h .rangee { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: .2rem .75rem; align-items: center; }
.barres-h .nom { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.barres-h .montant-h { font-variant-numeric: tabular-nums; font-weight: 600; font-size: .9rem; }
.barres-h .piste { grid-column: 1 / -1; height: 8px; background: var(--bleu-clair); border-radius: 0 4px 4px 0; overflow: hidden; }
.barres-h .remplissage { height: 100%; background: var(--bleu); border-radius: 0 4px 4px 0; }
.barres-h .nb { color: var(--sourd); font-weight: 400; font-size: .8rem; }

.chiffres-devis { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin-bottom: .8rem; }
.chiffres-devis div { background: var(--fond); border-radius: 10px; padding: .6rem .5rem; text-align: center; }
.chiffres-devis strong { display: block; font-size: 1.35rem; font-weight: 700; }
.chiffres-devis span { font-size: .78rem; color: var(--sourd); }
.jauge { height: 10px; border-radius: 5px; background: var(--bleu-clair); overflow: hidden; }
.jauge div { height: 100%; background: var(--bleu); border-radius: 5px; }

/* --- Page de connexion -------------------------------------------------------- */
.connexion-page { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.connexion-visuel {
  background: radial-gradient(1200px 600px at 20% 0%, #1e3a8a 0%, var(--lateral) 55%);
  color: #fff; padding: 3rem; display: flex; flex-direction: column; justify-content: space-between;
}
.connexion-visuel .marque { font-size: 1.4rem; }
.connexion-visuel h1 { font-size: 2.3rem; margin: 0 0 1rem; max-width: 16ch; }
.connexion-visuel p { color: #cbd5e1; font-size: 1.05rem; max-width: 42ch; }
.connexion-visuel ul { list-style: none; padding: 0; margin: 1.5rem 0 0; display: flex; flex-direction: column; gap: .7rem; }
.connexion-visuel li { display: flex; align-items: center; gap: .7rem; color: #e2e8f0; }
.connexion-visuel li .icone { color: #7db3f0; }
.connexion-visuel .pied { font-size: .82rem; color: #94a3b8; }
.connexion-form { display: grid; place-items: center; padding: 2rem; }
.connexion-form .carte { width: min(100%, 400px); padding: 2rem; }
.connexion-form h2 { font-size: 1.35rem; margin: 0 0 .25rem; }
.connexion-form .discret { margin-bottom: 1.25rem; }
.connexion-form button[type="submit"] { width: 100%; }

/* --- Document (devis / facture) --------------------------------------------- */
.ajout { margin-top: 1rem; padding-top: 1rem; border-top: 1px dashed var(--trait); }
.ajout details { margin-top: .75rem; }
.ajout summary { cursor: pointer; color: var(--bleu); padding: .4rem 0; font-weight: 500; }
.ajout details .grille { margin: .5rem 0; }
.resultats { display: flex; flex-direction: column; gap: .4rem; }
.resultat { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .45rem .6rem; border: 1px solid #eceef1; border-radius: 10px; background: #fafbfc; }
.resultat .nom { flex: 1; min-width: 160px; font-weight: 500; }
.tag { font-size: .72rem; font-weight: 600; padding: .12rem .5rem; border-radius: 4px; background: var(--bleu-clair); color: var(--bleu-fonce); text-transform: uppercase; letter-spacing: .03em; }
.tag.fourniture { background: var(--ok-fond); color: var(--ok); }

.totaux { max-width: 380px; margin-left: auto; }
.totaux > div { display: flex; justify-content: space-between; gap: 1rem; padding: .22rem 0; }
.totaux .ttc { border-top: 1px solid var(--trait); margin-top: .3rem; padding-top: .5rem; font-size: 1.15rem; }
.totaux .reste { color: var(--danger); }
.totaux .solde { color: var(--ok); }
dl.infos { display: grid; grid-template-columns: max-content 1fr; gap: .45rem 1rem; margin: 0; }
dl.infos dt { color: var(--sourd); }
dl.infos dd { margin: 0; }

/* --- Logo (reglages) ---------------------------------------------------------- */
.logo-zone { display: flex; flex-wrap: wrap; align-items: center; gap: 1.25rem; }
.logo-apercu {
  width: 220px; height: 110px; border: 1px dashed #cfd2d8; border-radius: 10px; display: grid; place-items: center;
  background: repeating-conic-gradient(#f3f4f6 0 25%, #fff 0 50%) 0 0 / 16px 16px; color: var(--sourd); font-size: .85rem;
}
.logo-apercu img { max-width: 100%; max-height: 100%; object-fit: contain; padding: 6px; }
input[type="file"] { display: none; }

/* --- Messages ------------------------------------------------------------------ */
#toasts { position: fixed; bottom: 1.25rem; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: .5rem; z-index: 100; width: min(92vw, 480px); }
.toast { display: flex; align-items: center; gap: .6rem; padding: .8rem 1rem; border-radius: 10px; color: #fff; background: #166534; box-shadow: 0 6px 20px rgba(0, 0, 0, .18); }
.toast.erreur { background: var(--danger); }

/* --- Ecrans etroits : barre d'onglets en bas ------------------------------- */
@media (max-width: 900px) {
  .deux-colonnes { grid-template-columns: minmax(0, 1fr); }
  .connexion-page { grid-template-columns: 1fr; }
  .connexion-visuel { padding: 2rem 1.5rem; min-height: 0; }
  .connexion-visuel h1 { font-size: 1.7rem; }
  .connexion-visuel ul, .connexion-visuel .pied { display: none; }
}
@media (max-width: 760px) {
  body.connecte { display: block; }
  /* Le menu reste dans le DOM (barre en bas) : seul le reste de la colonne laterale disparait. */
  body.connecte .lateral { display: contents; }
  body.connecte .lateral > .marque, body.connecte .lateral > .entreprise, body.connecte .lateral-pied { display: none; }
  body.connecte .entete-mobile {
    display: flex; align-items: center; gap: .75rem; padding: .6rem .9rem; background: var(--lateral); color: #fff;
    position: sticky; top: 0; z-index: 10;
  }
  .entete-mobile .marque { font-size: 1rem; }
  .entete-mobile .entreprise { flex: 1; min-width: 0; padding: 0; background: none; gap: .5rem; justify-content: flex-end; }
  .entete-mobile .entreprise .logo, .entete-mobile .entreprise .initiales { width: 32px; height: 32px; font-size: .8rem; }
  .entete-mobile .entreprise .nom { font-size: .8rem; text-align: right; }
  .entete-mobile .entreprise .role { display: none; }
  .entete-mobile .lien { width: auto; padding: .4rem; }
  body.connecte #menu {
    display: flex; flex-direction: row; position: fixed; bottom: 0; left: 0; right: 0; z-index: 10;
    background: #fff; border-top: 1px solid var(--bord); padding: .3rem .25rem calc(.3rem + env(safe-area-inset-bottom));
    box-shadow: 0 -4px 16px rgba(11, 11, 11, .06);
  }
  body.connecte #menu a { flex: 1; flex-direction: column; gap: .15rem; padding: .35rem 0; font-size: .68rem; color: var(--encre-2); border-radius: 8px; }
  body.connecte #menu a.actif { background: none; color: var(--bleu-fonce); }
  body.connecte #menu a.actif .icone { color: var(--bleu); }
  #app { padding: 1rem .9rem 5.5rem; }
  .titre h1 { font-size: 1.3rem; }
  .carte { padding: .9rem; }
  .totaux { max-width: none; }
  .kpi.hero .valeur { font-size: 2.1rem; }
  .listes { grid-template-columns: minmax(0, 1fr); }
}

@media print {
  .lateral, .entete-mobile, #menu, #toasts { display: none !important; }
}
