/* =============================================================================
   Gestion Locative – feuille de style unique, sans dépendance externe.
   Conception « mobile d'abord » :
     - smartphone : barre supérieure + menu latéral escamotable ;
     - à partir de 1024 px : menu latéral fixe.
   Thème clair / sombre automatique selon le réglage de l'appareil.
   ============================================================================= */

:root {
  --fond: #f4f6fa; --surface: #ffffff; --surface-2: #f8f9fc; --texte: #172033; --discret: #5b6476;
  --bordure: #e2e6ee; --accent: #3b5bdb; --accent-doux: #e8edff; --accent-texte: #ffffff;
  --ok: #1d7a45; --ok-doux: #e3f5ea; --alerte: #a65d00; --alerte-doux: #fff3e0; --erreur: #b3261e; --erreur-doux: #fdecea;
  --ombre: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --rayon: 12px; --largeur-menu: 260px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --fond: #0f131a; --surface: #171c25; --surface-2: #1c2230; --texte: #e7eaf0; --discret: #9aa4b5;
    --bordure: #2a3242; --accent: #7c95ff; --accent-doux: #1f2945; --accent-texte: #0b1020;
    --ok: #5cc98a; --ok-doux: #15301f; --alerte: #f0ad4e; --alerte-doux: #33260f; --erreur: #ff8a80; --erreur-doux: #3a1714;
    --ombre: none;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif; background: var(--fond); color: var(--texte); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.45rem; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 1.05rem; margin: 0 0 .75rem; }
code { font-size: .88em; background: var(--surface-2); padding: .05rem .3rem; border-radius: 4px; }
pre { white-space: pre-wrap; background: var(--surface-2); padding: .8rem; border-radius: 8px; border: 1px solid var(--bordure); font-size: .88rem; margin: 0; }
.icone { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* --- Structure : menu latéral + contenu ------------------------------------ */
.cadre { min-height: 100vh; }
.menu-lateral {
  position: fixed; inset: 0 auto 0 0; width: var(--largeur-menu); background: var(--surface); border-right: 1px solid var(--bordure);
  display: flex; flex-direction: column; z-index: 30; transform: translateX(-100%); transition: transform .2s ease;
}
.menu-ouvert .menu-lateral { transform: none; box-shadow: 0 0 40px rgba(0, 0, 0, .25); }
.voile { display: none; position: fixed; inset: 0; background: rgba(15, 19, 26, .45); z-index: 25; }
.menu-ouvert .voile { display: block; }
.marque { display: flex; align-items: center; gap: .6rem; padding: 1.1rem 1.2rem; font-weight: 700; font-size: 1.05rem; color: var(--texte); }
.marque .logo { width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: var(--accent-texte); display: grid; place-items: center; }
.marque .logo .icone { width: 18px; height: 18px; }
.navigation { flex: 1; overflow-y: auto; padding: .25rem .75rem 1rem; }
.rubrique { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--discret); padding: 1rem .6rem .35rem; }
.lien-menu { display: flex; align-items: center; gap: .7rem; padding: .55rem .6rem; border-radius: 8px; color: var(--texte); font-weight: 500; }
.lien-menu:hover { background: var(--surface-2); text-decoration: none; }
.lien-menu.actif { background: var(--accent-doux); color: var(--accent); }
.pied-menu { border-top: 1px solid var(--bordure); padding: .75rem; display: flex; flex-direction: column; gap: .15rem; }
.pied-menu .version { color: var(--discret); font-size: .78rem; padding: .3rem .6rem; }

.barre-haute { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: .75rem; padding: .6rem 16px;
  background: var(--surface); border-bottom: 1px solid var(--bordure); }
.barre-haute .titre-app { font-weight: 700; }
.contenu { padding: 20px 16px 48px; max-width: 1240px; margin: 0 auto; }

@media (min-width: 1024px) {
  .menu-lateral { transform: none; }
  .voile, .barre-haute { display: none !important; }
  .principal { margin-left: var(--largeur-menu); }
  .contenu { padding: 28px 32px 64px; }
}

/* --- En-tête de page ---------------------------------------------------------- */
.entete-page { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem 1rem; margin-bottom: 1.25rem; }
.entete-page .sous-titre { color: var(--discret); margin-top: .2rem; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }

/* --- Cartes ------------------------------------------------------------------- */
.carte { background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 18px; box-shadow: var(--ombre); margin-bottom: 16px; }
.grille { display: grid; gap: 16px; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); margin-bottom: 16px; }
.indicateur { display: flex; flex-direction: column; gap: .35rem; color: var(--texte); }
.indicateur:hover { text-decoration: none; border-color: var(--accent); }
.indicateur .valeur { font-size: 2rem; font-weight: 700; line-height: 1.1; }
.indicateur .libelle { color: var(--discret); }
.indicateur.alerte .valeur { color: var(--alerte); }
.titre-groupe { display: flex; align-items: center; gap: .5rem; font-weight: 600; margin: .5rem 0 .75rem; color: var(--discret); }
.discret { color: var(--discret); font-size: .88rem; }
.texte-erreur { color: var(--erreur); font-weight: 600; }
.vide { text-align: center; color: var(--discret); padding: 2rem 1rem; }

/* --- Onglets ------------------------------------------------------------------ */
.onglets { display: flex; gap: .25rem; overflow-x: auto; border-bottom: 1px solid var(--bordure); margin-bottom: 1.25rem; scrollbar-width: thin; }
.onglets a { padding: .6rem .9rem; color: var(--discret); white-space: nowrap; border-bottom: 2px solid transparent; font-weight: 500; }
.onglets a:hover { color: var(--texte); text-decoration: none; }
.onglets a.actif { color: var(--accent); border-bottom-color: var(--accent); }

/* --- Tableaux : défilement horizontal sur petit écran ------------------------- */
.tableau { overflow-x: auto; background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); box-shadow: var(--ombre); margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .7rem .9rem; border-bottom: 1px solid var(--bordure); vertical-align: top; }
tr:last-child td { border-bottom: 0; }
th { font-size: .78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--discret); font-weight: 600; background: var(--surface-2); }
tbody tr:hover { background: var(--surface-2); }
td .secondaire { display: block; color: var(--discret); font-size: .84rem; }

/* --- Formulaires ---------------------------------------------------------------- */
fieldset { border: 1px solid var(--bordure); border-radius: var(--rayon); padding: 16px 18px 4px; margin: 0 0 16px; background: var(--surface); box-shadow: var(--ombre); }
legend { font-weight: 650; padding: 0 .4rem; }
.champ { margin-bottom: 1rem; }
.champ label { display: block; font-weight: 550; margin-bottom: .3rem; font-size: .92rem; }
.champ .aide { color: var(--discret); font-size: .82rem; margin-top: .25rem; }
.champ .erreurs, .erreurs { color: var(--erreur); font-size: .88rem; }
input[type=text], input[type=email], input[type=url], input[type=number], input[type=date], input[type=password], input[type=file], input:not([type]), select, textarea {
  width: 100%; padding: .6rem .7rem; font: inherit; color: inherit; background: var(--surface-2); border: 1px solid var(--bordure); border-radius: 8px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: 0; border-color: var(--accent); }
input[type=checkbox] { width: 1.1rem; height: 1.1rem; accent-color: var(--accent); vertical-align: middle; }
.champ-case label { display: flex; align-items: center; gap: .5rem; }
@media (min-width: 900px) { .grille-champs { display: grid; grid-template-columns: 1fr 1fr; column-gap: 24px; } .champ.large { grid-column: 1 / -1; } }
.tableau-formulaire td { padding: .4rem; }
.tableau-formulaire input, .tableau-formulaire textarea { min-width: 110px; }
.barre-enregistrer { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--fond) 30%); padding: 1rem 0 .25rem; display: flex; gap: .5rem; }

/* --- Boutons ---------------------------------------------------------------- */
.bouton, button { display: inline-flex; align-items: center; gap: .45rem; padding: .55rem 1rem; font: inherit; font-weight: 550; border-radius: 8px;
  border: 1px solid var(--accent); background: var(--accent); color: var(--accent-texte); cursor: pointer; text-decoration: none; line-height: 1.2; }
.bouton:hover, button:hover { filter: brightness(1.07); text-decoration: none; }
.bouton.secondaire, button.secondaire { background: var(--surface); color: var(--accent); border-color: var(--bordure); }
.bouton.discret, button.discret { background: transparent; border-color: transparent; color: var(--discret); }
button.lien { background: none; border: 0; color: var(--accent); padding: 0; font-weight: 500; }
button:disabled { opacity: .5; cursor: not-allowed; }
.bouton-menu { background: transparent; border: 1px solid var(--bordure); color: var(--texte); padding: .45rem .6rem; }
form.en-ligne { display: inline; }
.filtres { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: 1rem; }
.filtres a { padding: .35rem .8rem; border-radius: 999px; border: 1px solid var(--bordure); background: var(--surface); color: var(--discret); font-size: .9rem; }
.filtres a.actif { background: var(--accent-doux); color: var(--accent); border-color: transparent; }

/* --- Messages et états -------------------------------------------------------- */
.message { padding: .8rem 1rem; border-radius: 10px; margin-bottom: .75rem; border: 1px solid var(--bordure); background: var(--surface); white-space: pre-line; }
.message.success { background: var(--ok-doux); border-color: transparent; }
.message.warning { background: var(--alerte-doux); border-color: transparent; }
.message.error { background: var(--erreur-doux); border-color: transparent; }
.etat { display: inline-flex; align-items: center; gap: .3rem; padding: .12rem .55rem; border-radius: 999px; font-size: .78rem; font-weight: 600; white-space: nowrap; }
.etat.ok { color: var(--ok); background: var(--ok-doux); }
.etat.alerte { color: var(--alerte); background: var(--alerte-doux); }
.etat.erreur { color: var(--erreur); background: var(--erreur-doux); }
.etat.neutre { color: var(--discret); background: var(--surface-2); }
ul.problemes { margin: .4rem 0 0; padding-left: 1.1rem; color: var(--alerte); font-size: .9rem; }
.connexion { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.connexion .carte { width: 100%; max-width: 400px; padding: 28px; }

/* --- Tableaux « empilables » : sur smartphone, chaque ligne devient une carte -----
   Chaque cellule porte data-libelle="Titre de colonne", affiché devant la valeur. */
td code { white-space: nowrap; }
@media (max-width: 720px) {
  table.empilable thead { display: none; }
  table.empilable, table.empilable tbody, table.empilable tr, table.empilable td { display: block; width: 100%; }
  table.empilable tr { padding: .6rem .9rem; border-bottom: 1px solid var(--bordure); }
  table.empilable td { border: 0; padding: .2rem 0; position: relative; }
  table.empilable td[data-libelle] { padding-left: 7.5rem; min-height: 1.6rem; }
  table.empilable td[data-libelle]::before { content: attr(data-libelle); position: absolute; left: 0; top: .3rem; width: 7rem; color: var(--discret); font-size: .8rem; }
  table.empilable td.case-selection { text-align: right; }
  .barre-enregistrer { flex-wrap: wrap; }
}

/* --- États des lieux : saisie sur téléphone (grandes zones tactiles) --- */
.edl-liste { display: flex; flex-direction: column; gap: .6rem; margin-bottom: 1rem; }
.edl-ligne { display: flex; justify-content: space-between; align-items: center; gap: .75rem; padding: .85rem 1rem; min-height: 48px;
  background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); color: var(--texte); text-decoration: none; }
.edl-ligne.element { border-radius: 8px; margin: .35rem .5rem 0; }
.edl-ligne.valide { background: var(--ok-doux); border-color: var(--ok); }
.edl-piece { background: var(--surface); border: 1px solid var(--bordure); border-radius: var(--rayon); padding-bottom: .5rem; }
.edl-piece.complete { border-color: var(--ok); }
.edl-piece > summary { display: flex; justify-content: space-between; gap: .75rem; padding: 1rem; cursor: pointer; font-weight: 600; min-height: 48px; }
.edl-piece.complete > summary { color: var(--ok); }
.edl-piece > .edl-ligne:first-of-type { margin: 0 .5rem; border-style: dashed; }
.pastille { font-size: .8rem; color: var(--discret); text-align: right; }
.pastille.ok { color: var(--ok); }
.carte.complete { border: 1px solid var(--ok); }
.carte.reference { background: var(--surface-2); }
.choix-etat { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: .5rem; border: 0; padding: 0; }
.choix-etat legend { font-weight: 600; margin-bottom: .4rem; }
.choix-etat label { display: flex; align-items: center; gap: .4rem; padding: .8rem; min-height: 48px; border: 1px solid var(--bordure);
  border-radius: 10px; background: var(--surface-2); cursor: pointer; }
.choix-etat label:has(input:checked), .choix-etat label.choisi { border-color: var(--accent); background: var(--accent-doux); font-weight: 600; }
.champ.quantite input { max-width: 8rem; font-size: 1.3rem; }
.champ.quantite .attendu { margin-left: .75rem; }
.photos { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; }
.vignette { position: relative; margin: 0; width: 96px; height: 96px; }
.vignette img { width: 96px; height: 96px; object-fit: cover; border-radius: 8px; border: 1px solid var(--bordure); }
.vignette .supprimer { position: absolute; top: -8px; right: -8px; width: 28px; height: 28px; padding: 0; border-radius: 50%; justify-content: center; }
.bouton-photo { display: inline-flex; align-items: center; justify-content: center; width: 96px; height: 96px; border: 2px dashed var(--accent);
  border-radius: 8px; color: var(--accent); font-weight: 600; cursor: pointer; }
.bouton-photo input { display: none; }
.etat-envoi { font-size: .85rem; color: var(--discret); }
.zone-signature { width: 100%; height: 180px; border: 1px dashed var(--bordure); border-radius: 8px; background: #fff; touch-action: none; }
.zone-signature.paraphe { height: 120px; max-width: 260px; }

button.danger { background: var(--erreur); border-color: var(--erreur); color: #fff; }

/* États des lieux (1.3.0) : rubriques de pièce, lignes d'items avec choix de l'état, navigation */
.edl-rubrique { display: flex; flex-direction: column; gap: .2rem; padding: 1rem; min-height: 56px; background: var(--surface);
  border: 1px solid var(--bordure); border-radius: var(--rayon); color: var(--texte); text-decoration: none; }
.edl-rubrique .nom { font-weight: 650; }
.edl-rubrique.complete { background: var(--ok-doux); border-color: var(--ok); }
.manque, .item-photo.manque { color: var(--erreur); font-weight: 600; }
.carte.manque { border: 1px solid var(--erreur); }
.items { display: flex; flex-direction: column; gap: .5rem; margin-bottom: 1rem; }
.item { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .5rem; padding: .7rem .8rem;
  background: var(--surface); border: 1px solid var(--bordure); border-radius: 10px; }
.item.valide { background: var(--ok-doux); border-color: var(--ok); }
.item-nom { display: flex; flex-direction: column; gap: .15rem; color: var(--texte); text-decoration: none; font-weight: 600; flex: 1 1 12rem; }
.item-photo { font-size: .8rem; font-weight: 400; color: var(--discret); }
.item-photo.ok { color: var(--ok); }
.item-saisie { display: flex; align-items: center; gap: .5rem; flex-wrap: wrap; }
.item-saisie select { min-height: 44px; min-width: 9.5rem; }
.item-quantite input { width: 4.5rem; min-height: 44px; font-size: 1.05rem; }
.navigation-edl { display: flex; justify-content: space-between; gap: 1rem; margin: .5rem 0 1rem; }
.navigation-edl a { padding: .6rem .2rem; font-weight: 600; }
dl.informations { display: grid; grid-template-columns: minmax(8rem, max-content) 1fr; gap: .35rem 1rem; margin: .75rem 0; }
dl.informations dt { color: var(--discret); }
dl.informations dd { margin: 0; }
.bouton.danger, button.danger { background: var(--erreur); border-color: var(--erreur); color: #fff; }
/* Boutons d'une ligne de tableau (1.7.0) : compacts ; suppression en contour rouge, discrète. */
.bouton.petit, button.petit { padding: .2rem .55rem; font-size: .8rem; font-weight: 500; border-radius: 6px; }
.bouton.danger.contour, button.danger.contour { background: transparent; color: var(--erreur); }
@media (max-width: 640px) { dl.informations { grid-template-columns: 1fr; gap: 0; } dl.informations dd { margin-bottom: .5rem; } }

/* Boutons d'état (couleur réglée dans l'échelle d'état) et lignes cliquables (1.4.0) */
.etats-boutons { display: flex; flex-wrap: wrap; gap: .3rem; }
.etat-bouton { padding: .35rem .5rem; min-height: 40px; font-size: .78rem; font-weight: 600; border-radius: 8px;
  background: var(--surface); color: var(--texte); border: 2px solid var(--bordure); opacity: .75; }
.etat-bouton.choisi { opacity: 1; box-shadow: 0 0 0 2px var(--texte) inset; }
.couleur-vert { border-color: #1d7a45; } .etat-bouton.couleur-vert.choisi, .choix-etat label.couleur-vert.choisi { background: #1d7a45; color: #fff; }
.couleur-vert_pale { border-color: #7cc49a; } .etat-bouton.couleur-vert_pale.choisi, .choix-etat label.couleur-vert_pale.choisi { background: #b9e4c9; color: #10301c; }
.couleur-orange { border-color: #e08a00; } .etat-bouton.couleur-orange.choisi, .choix-etat label.couleur-orange.choisi { background: #f5a623; color: #2b1a00; }
.couleur-rouge { border-color: #c62828; } .etat-bouton.couleur-rouge.choisi, .choix-etat label.couleur-rouge.choisi { background: #c62828; color: #fff; }
.couleur-gris { border-color: #9aa4b5; } .etat-bouton.couleur-gris.choisi, .choix-etat label.couleur-gris.choisi { background: #9aa4b5; color: #111; }
.choix-etat label { border-width: 2px; }
tr[data-lien] { cursor: pointer; }
tr[data-lien]:hover td { background: var(--surface-2); }
