/* ===== Couleurs (mode clair et mode sombre automatique) ===== */
:root {
  --fond: #eef0f3;
  --carte: #ffffff;
  --texte: #1b1d21;
  --discret: #646a73;
  --bordure: #dde1e6;
  --accent: #ffc400;          /* jaune électrique */
  --accent-doux: #fff4cc;
  --sombre: #1b1d21;          /* en-tête et barre du bas */
  --ok: #1f8a4c;
  --erreur: #c62828;
  --ombre: 0 1px 3px rgba(0, 0, 0, .08);
  /* couleurs des fils dans les schémas */
  --fil-phase: #d32f2f;
  --fil-neutre: #1e6fd9;
  --fil-retour: #ef7d00;
  --fil-navette: #8e44ad;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --fond: #111315;
    --carte: #1c1f23;
    --texte: #eef0f3;
    --discret: #9aa1ab;
    --bordure: #2c3036;
    --accent-doux: #3a3210;
    --sombre: #0b0c0e;
    --ok: #4cc27f;
    --erreur: #ff6b5b;
    --ombre: none;
    --fil-phase: #ff5a52;
    --fil-neutre: #5aa2ff;
    --fil-retour: #ffa133;
    --fil-navette: #c08ae0;
  }
}
/* Mêmes valeurs quand le mode sombre est choisi à la main */
:root[data-theme="dark"] {
  color-scheme: dark;
  --fond: #111315;
  --carte: #1c1f23;
  --texte: #eef0f3;
  --discret: #9aa1ab;
  --bordure: #2c3036;
  --accent-doux: #3a3210;
  --sombre: #0b0c0e;
  --ok: #4cc27f;
  --erreur: #ff6b5b;
  --ombre: none;
  --fil-phase: #ff5a52;
  --fil-neutre: #5aa2ff;
  --fil-retour: #ffa133;
  --fil-navette: #c08ae0;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--fond);
  color: var(--texte);
  line-height: 1.5;
  padding-bottom: 90px; /* place pour la barre du bas */
}

/* ===== En-tête + recherche ===== */
header {
  background: var(--sombre);
  color: #fff;
  padding: 12px 16px;
  position: sticky; top: env(safe-area-inset-top, 0px); z-index: 10;
}
.entete-haut { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; max-width: 720px; margin-inline: auto; }
.logo {
  width: 42px; height: 42px; border-radius: 10px;
  background: var(--accent);
  display: grid; place-items: center;
  font-size: 1.5rem;
}
header h1 { margin: 0; font-size: 1.3rem; letter-spacing: .5px; }
.sous-titre { margin: 0; font-size: .8rem; color: #b8bec7; }
#recherche {
  display: block; width: 100%; max-width: 720px; margin: 0 auto;
  padding: 10px 14px; font-size: 1rem;
  border: none; border-radius: 10px;
  background: #2c3036; color: #fff;
}
#recherche::placeholder { color: #9aa1ab; }
#recherche:focus { outline: 2px solid var(--accent); }

main { max-width: 720px; margin: 0 auto; padding: 8px 16px; }
h2 { font-size: 1.2rem; margin: 20px 0 8px; }
h3 { font-size: 1rem; margin: 16px 0 8px; }
.carte h2, .carte h3:first-child { margin-top: 0; }
.intro { color: var(--discret); margin: 0 0 12px; font-size: .95rem; }

/* ===== Onglets ===== */
.onglet, .sous-calcul { display: none; }
.onglet.actif, .sous-calcul.actif { display: block; }

/* Pendant une recherche, on cache les onglets et on montre les résultats */
#resultats-recherche { display: none; }
.recherche-active #resultats-recherche { display: block; }
.recherche-active .onglet.actif { display: none; }

.resultat-recherche {
  display: block; width: 100%; text-align: left;
  color: var(--texte); font-size: 1rem; cursor: pointer;
}
.resultat-recherche span { display: block; color: var(--discret); font-size: .9rem; margin-top: 2px; }

nav {
  position: fixed; bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--sombre);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
}
nav button {
  flex: 1;
  background: none; border: none;
  padding: 10px 0 12px;
  color: #8d949e;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  font-size: .7rem;
  cursor: pointer;
  border-top: 3px solid transparent;
}
nav button .ico { font-size: 1.35rem; filter: grayscale(1); opacity: .7; }
nav button.actif { color: #fff; font-weight: 600; border-top-color: var(--accent); }
nav button.actif .ico { filter: none; opacity: 1; }

/* ===== Cartes ===== */
.carte {
  background: var(--carte);
  border: 1px solid var(--bordure);
  border-radius: 14px;
  padding: 16px;
  margin-bottom: 12px;
  box-shadow: var(--ombre);
}
.titre-ligne { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.titre-ligne h2 { margin: 0; }

/* ===== Grille des pièces ===== */
.grille {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  gap: 10px;
}
.bouton-piece {
  background: var(--carte);
  border: 2px solid var(--bordure);
  border-radius: 14px;
  padding: 14px 6px;
  font-size: .9rem; font-weight: 500;
  color: var(--texte);
  cursor: pointer;
  box-shadow: var(--ombre);
}
.bouton-piece .emoji { display: block; font-size: 2rem; margin-bottom: 4px; }
.bouton-piece.actif { border-color: var(--accent); background: var(--accent-doux); }

/* ===== Pastilles de choix (calculateurs) ===== */
.pastilles { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 8px; margin-bottom: 8px; }
.pastilles button {
  flex-shrink: 0;
  padding: 10px 16px;
  border-radius: 999px;
  border: 2px solid var(--bordure);
  background: var(--carte);
  color: var(--texte);
  font-size: .9rem; font-weight: 500;
  cursor: pointer;
}
.pastilles button.actif { background: var(--accent); border-color: var(--accent); color: #1b1d21; font-weight: 700; }

/* ===== Formulaires ===== */
label { display: block; margin-bottom: 14px; font-size: .9rem; color: var(--discret); }
label small { display: block; margin-top: 2px; }
input[type="number"], input[type="text"], input[type="date"], select, textarea {
  display: block; width: 100%;
  margin-top: 4px; padding: 12px;
  font-size: 1.05rem; font-family: inherit;
  border: 2px solid var(--bordure);
  border-radius: 10px;
  background: var(--fond); color: var(--texte);
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); }
input[type="range"] { width: 100%; accent-color: var(--accent); margin-top: 8px; }
.deux-colonnes { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; align-items: end; }
.cases { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; margin-bottom: 8px; }
.cases label { display: flex; align-items: center; gap: 8px; color: var(--texte); margin-bottom: 10px; }
.cases input { width: 20px; height: 20px; accent-color: var(--accent); flex-shrink: 0; }

button[type="submit"], .secondaire, .principal {
  width: 100%; padding: 14px;
  font-size: 1.05rem; font-weight: 700;
  border-radius: 10px; border: none;
  background: var(--accent); color: #1b1d21;
  cursor: pointer;
  margin-bottom: 8px;
}
.secondaire { background: var(--bordure); color: var(--texte); font-weight: 600; }
.danger { color: var(--erreur); }
.a-confirmer { background: var(--erreur) !important; color: #fff !important; }
.petit-bouton.a-confirmer { width: auto; padding: 0 10px; }
.lien { background: none; border: none; color: var(--discret); font-size: 1rem; padding: 8px 0; cursor: pointer; }
.petit-bouton {
  background: var(--bordure); color: var(--texte);
  border: none; border-radius: 8px;
  width: 36px; height: 36px; flex-shrink: 0;
  cursor: pointer;
}

/* ===== Résultats ===== */
.resultat { border-left: 5px solid var(--accent); }
.resultat p { margin: 6px 0; }
.chiffre { font-size: 1.7rem; font-weight: 800; }
.ok { color: var(--ok); }
.erreur { color: var(--erreur); }
.info { background: var(--accent-doux); border-radius: 8px; padding: 8px 10px; font-size: .9rem; }

ul.regles, ol.regles { padding-left: 20px; margin: 8px 0 0; }
.regles li { margin-bottom: 6px; }

/* ===== Sources et badges ===== */
.source { font-size: .8rem; color: var(--discret); margin: 12px 0 0; }
.badge { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: .75rem; font-weight: 600; white-space: nowrap; }
.alerte-badge { background: var(--accent-doux); color: var(--texte); }
.ok-badge { background: var(--ok); color: #fff; }

/* ===== Favoris ===== */
.etoile {
  background: none; border: none;
  font-size: 1.5rem; line-height: 1;
  color: var(--discret); cursor: pointer;
  padding: 4px; margin-left: auto;
}
.etoile.actif { color: var(--accent); }
.favoris { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 8px; }
.favoris .intro { margin: 0; }
.pastille-favori {
  padding: 8px 14px; border-radius: 999px;
  border: 2px solid var(--accent); background: var(--accent-doux);
  color: var(--texte); font-size: .9rem; cursor: pointer;
}

/* ===== Bilan de puissance ===== */
.appareil { display: flex; align-items: center; gap: 10px; padding: 6px 0; border-bottom: 1px solid var(--bordure); margin: 0; color: var(--texte); }
.appareil input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--accent); flex-shrink: 0; }
.appareil span { flex: 1; }
.appareil input[type="number"] { width: 90px; margin: 0; padding: 6px 8px; font-size: .95rem; }

/* ===== Générateur de tableau ===== */
.differentiel h3 { display: flex; justify-content: space-between; gap: 8px; margin-top: 0; }
.compteur { background: var(--accent-doux); border-radius: 999px; padding: 0 10px; font-size: .85rem; white-space: nowrap; }
.differentiel td:first-child { font-weight: 500; }

/* ===== Fiches (accordéon) ===== */
details.carte { padding: 0; }
details summary {
  padding: 14px 16px;
  font-weight: 600; font-size: 1.05rem;
  cursor: pointer;
  list-style: none;
  display: flex; align-items: center; gap: 10px;
}
details summary::-webkit-details-marker { display: none; }
details summary::after { content: "›"; font-size: 1.5rem; color: var(--discret); transition: transform .2s; }
details[open] summary::after { transform: rotate(90deg); }
details .contenu { padding: 0 16px 16px; }
details h3 { font-size: .95rem; margin: 12px 0 6px; color: var(--discret); }

/* ===== Tableaux ===== */
.tableau-scroll { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--bordure); vertical-align: top; }
th { color: var(--discret); font-weight: 600; }
td:first-child { font-weight: 600; }

/* ===== Schémas de câblage ===== */
.schema svg { width: 100%; max-width: 440px; height: auto; display: block; margin: 12px auto 0; }
.schema text { fill: var(--texte); font-size: 13px; }
.schema .sch-petit { font-size: 10px; fill: var(--discret); }
.schema .sch-titre { font-weight: 700; }
.sch-phase, .sch-neutre, .sch-retour, .sch-navette { fill: none; stroke-width: 3; stroke-linecap: round; stroke-linejoin: round; }
.sch-phase { stroke: var(--fil-phase); }
.sch-neutre { stroke: var(--fil-neutre); }
.sch-retour { stroke: var(--fil-retour); }
.sch-navette { stroke: var(--fil-navette); }
.sch-composant { fill: none; stroke: var(--texte); stroke-width: 2; }
.sch-boite { fill: var(--fond); stroke: var(--texte); stroke-width: 1.5; }
.sch-borne { fill: var(--texte); }
.legende { font-size: .8rem; color: var(--discret); display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; }
.trait { display: inline-block; width: 18px; height: 4px; border-radius: 2px; margin-right: 4px; vertical-align: middle; }
.sch-phase-fond { background: var(--fil-phase); }
.sch-neutre-fond { background: var(--fil-neutre); }
.sch-retour-fond { background: var(--fil-retour); }
.sch-navette-fond { background: var(--fil-navette); }

/* ===== Carnet de chantier ===== */
.verdict { margin: -8px 0 12px; font-size: .9rem; font-weight: 600; }
.ligne-differentiel { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.ligne-differentiel input[type="checkbox"] { width: 24px; height: 24px; accent-color: var(--ok); flex-shrink: 0; }
.ligne-differentiel input[type="text"] { margin: 0; padding: 8px 10px; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 10px; }
.photo { margin: 0; position: relative; }
.photo img { width: 100%; aspect-ratio: 4 / 3; object-fit: cover; border-radius: 10px; display: block; }
.photo input { padding: 6px 8px; font-size: .85rem; }
.photo .petit-bouton { position: absolute; top: 6px; right: 6px; background: rgba(0, 0, 0, .6); color: #fff; }
.bouton-photo {
  display: block; text-align: center;
  padding: 14px; border-radius: 10px;
  border: 2px dashed var(--bordure);
  color: var(--texte); font-weight: 600; cursor: pointer; margin: 0;
}

/* ===== Plan électrique ===== */
.outils-plan button { display: inline-flex; align-items: center; gap: 6px; padding: 8px 12px; }
.mini-symbole { width: 22px; height: 22px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 0.035; }
.mini-symbole .sym-plein { fill: currentColor; }
.mini-symbole .sym-texte { fill: currentColor; stroke: none; font-weight: 700; font-family: system-ui, sans-serif; }
.actions-plan { display: flex; gap: 8px; margin-bottom: 8px; }
.petit-bouton.large { width: auto; padding: 0 14px; }
.petit-bouton:disabled { opacity: .4; cursor: default; }
.cadre-plan {
  overflow: auto; max-height: 70vh;
  border: 1px solid var(--bordure); border-radius: 12px;
  background: var(--carte); margin-bottom: 12px;
}
#svg-plan { display: block; min-width: 100%; height: auto; user-select: none; -webkit-user-select: none; }
.plan-fond { fill: var(--carte); }
.grille-fine { stroke: var(--bordure); stroke-width: 0.01; }
.grille { stroke: var(--bordure); stroke-width: 0.025; }
.plan-piece rect { fill: var(--accent); fill-opacity: .08; stroke: var(--texte); stroke-width: 0.06; }
.plan-piece text { fill: var(--texte); font-family: system-ui, sans-serif; }
.plan-piece .piece-nom { font-weight: 700; }
.plan-piece .piece-surface { fill: var(--discret); }
.plan-piece.selection rect { stroke: var(--accent); stroke-width: 0.1; fill-opacity: .18; }
.plan-symbole { fill: none; stroke: var(--texte); stroke-width: 0.035; }
.plan-symbole .sym-plein { fill: var(--texte); }
.plan-symbole .sym-texte { fill: var(--texte); stroke: none; font-weight: 700; font-family: system-ui, sans-serif; }
.plan-symbole .zone-clic { fill: transparent; stroke: none; }
.plan-symbole.selection .zone-clic { fill: var(--accent); fill-opacity: .35; }
.apercu-piece { fill: var(--accent); fill-opacity: .2; stroke: var(--accent); stroke-width: 0.06; stroke-dasharray: 0.2 0.1; }
.verif-plan ul { list-style: none; padding: 0; margin: 4px 0 12px; }
.verif-plan li { margin-bottom: 2px; }
.verif-piece { border-bottom: 1px solid var(--bordure); padding-top: 8px; }
.case-simple { display: flex; align-items: center; gap: 8px; color: var(--texte); }
.case-simple input { width: 20px; height: 20px; accent-color: var(--accent); }
.legende-plan { display: flex; flex-wrap: wrap; gap: 6px 18px; }
.legende-plan span { display: inline-flex; align-items: center; gap: 6px; }

/* ===== Check-list ===== */
.point { display: flex; gap: 12px; align-items: flex-start; padding: 10px 0; color: var(--texte); margin: 0; font-size: .95rem; border-bottom: 1px solid var(--bordure); }
.point:last-child { border-bottom: none; }
.point input { width: 24px; height: 24px; margin: 0; flex-shrink: 0; accent-color: var(--ok); }
.progression { font-weight: 700; margin: 0 0 8px; }
.barre { height: 10px; background: var(--bordure); border-radius: 999px; overflow: hidden; }
#barre-remplie { height: 100%; width: 0; background: var(--ok); transition: width .3s; }

/* ===== Bloc « Donner mon avis » ===== */
.avis { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; margin-top: 32px; border: 2px solid var(--accent); }
.avis > div { flex: 1 1 240px; min-width: 0; }
.avis p { margin: 4px 0 0; color: var(--discret); font-size: .9rem; }
.avis a.principal { display: block; flex: 1 1 180px; text-align: center; text-decoration: none; margin: 0; }

.avertissement { font-size: .8rem; color: var(--discret); text-align: center; margin-top: 32px; }

/* ===== Petits écrans ===== */
@media (max-width: 380px) {
  .deux-colonnes, .cases { grid-template-columns: 1fr; }
}

/* ===== Impression / PDF ===== */
#rapport { display: none; }
@media print {
  body { background: #fff; color: #000; padding: 0; }
  header, nav, form, .pastilles, .avertissement, button, #resultats-recherche { display: none !important; }
  .carte { box-shadow: none; border-color: #ccc; break-inside: avoid; }
  /* Rapport de chantier : on n'imprime que lui */
  .impression-rapport main { display: none; }
  .impression-rapport #rapport { display: block; padding: 0 8mm; }
  #rapport h1 { font-size: 1.5rem; }
  #rapport .notes { white-space: pre-wrap; }
  .rapport-photos { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
  .rapport-photos figure { margin: 0; break-inside: avoid; }
  .rapport-photos img { width: 100%; border-radius: 6px; }
  .rapport-photos figcaption { font-size: .85rem; }
  .plan-imprime { width: 100%; height: auto; border: 1px solid #999; break-inside: avoid; }
  #rapport ul { list-style: none; padding-left: 0; }
}
