/* ============================================================
   Simulateur de devis — Home Elec
   Charte reprise du site home-elec (bleu marine + vert).
   ============================================================ */
:root {
  /* Palette Home Elec */
  --blue: #1E3A5F;
  --blue-dark: #142A47;
  --blue-light: #5B8AB8;
  --green: #3D8B5E;
  --green-dark: #2F6E4A;
  --bg: #F5F7F4;
  --bg-alt: #ECEFE9;
  --card: #FFFFFF;
  --txt: #2C3E50;
  --muted: #5A6B7B;
  --line: #D8DEE3;
  --error: #B0303C;
  --ok: #2F6E4A;
  --warn: #C4781A;
  --bad: #B0303C;

  --radius: 14px;
  --shadow: 0 2px 6px rgba(30, 58, 95, 0.08);
  --shadow-md: 0 8px 24px rgba(30, 58, 95, 0.10);

  --ff-head: "Manrope", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ff-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--ff-body);
  background: var(--bg);
  color: var(--txt);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  -webkit-tap-highlight-color: transparent;
}
h1, h2, h3 { font-family: var(--ff-head); letter-spacing: -0.01em; }

/* --- App bar --- */
.appbar {
  background: var(--blue);
  color: #fff;
  padding: max(env(safe-area-inset-top), 12px) 16px 12px;
  position: sticky;
  top: 0;
  z-index: 10;
  box-shadow: var(--shadow);
}
.appbar-title { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.appbar-logo { height: 30px; width: auto; display: block; }
.appbar small { color: #9DB6CE; font-size: 11px; font-weight: 600; }
/* repli si le logo ne charge pas */
.appbar h1 { font-size: 17px; margin: 0; font-weight: 800; color: #fff; }

/* --- Panneaux --- */
.panels {
  flex: 1;
  overflow-y: auto;
  /* dégage la barre d'onglets + l'indicateur d'accueil iPhone */
  padding: 14px 14px calc(86px + env(safe-area-inset-bottom));
  -webkit-overflow-scrolling: touch;
}
.panel { display: flex; flex-direction: column; gap: 14px; }
/* CRITIQUE : `display:flex` ci-dessus écraserait l'attribut [hidden] du
   navigateur → sans cette règle, tous les onglets s'affichent empilés.
   Spécificité .panel[hidden] (0,2,0) > .panel (0,1,0) : le masquage gagne. */
.panel[hidden] { display: none; }

/* --- Cartes --- */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px;
  border: 1px solid #eef1ef;
}
.card h2 {
  font-size: 15px;
  margin: 0 0 12px;
  color: var(--blue);
  display: flex;
  align-items: baseline;
  gap: 6px;
  font-weight: 800;
}
.card h2 small { color: var(--muted); font-weight: 500; font-size: 11px; }
.hint { color: var(--muted); font-size: 12px; margin: -6px 0 10px; }
.muted { color: var(--muted); font-size: 13px; }

/* --- Champs --- */
label {
  display: flex;
  flex-direction: column;
  font-size: 12px;
  color: var(--muted);
  gap: 5px;
  margin-bottom: 12px;
  font-weight: 600;
}
label:last-child { margin-bottom: 0; }
input, select, textarea {
  font: inherit;
  font-size: 16px;
  color: var(--txt);
  background: #fbfcfb;
  border: 1.5px solid var(--line);
  border-radius: 10px;
  padding: 11px 12px;
  width: 100%;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--blue-light);
  box-shadow: 0 0 0 3px rgba(91, 138, 184, 0.15);
}
textarea { resize: vertical; }
/* Champs nombre : on masque les flèches (place gagnée + rendu propre sur Mac) */
input[type="number"]::-webkit-inner-spin-button,
input[type="number"]::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check {
  flex-direction: row;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--txt);
  font-weight: 600;
}
.check input { width: auto; }

/* --- Boutons --- */
button { font: inherit; cursor: pointer; border: none; border-radius: 10px; }
.btn-primary {
  background: var(--blue);
  color: #fff;
  padding: 13px;
  width: 100%;
  font-weight: 700;
  font-size: 15px;
  transition: background .15s;
}
.btn-primary:hover { background: var(--blue-dark); }
.btn-primary:disabled { opacity: .6; }
.btn-secondary {
  background: var(--bg-alt);
  color: var(--blue);
  padding: 12px;
  font-weight: 700;
  flex: 1;
}
.btn-ghost {
  background: transparent;
  color: var(--bad);
  padding: 12px;
  width: 100%;
  font-weight: 600;
  border: 1.5px dashed var(--line);
}
.btn-row { display: flex; gap: 10px; }

/* --- Chips prestations --- */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  background: var(--bg-alt);
  color: var(--blue);
  border: 1.5px solid var(--line);
  border-radius: 999px;
  padding: 12px 16px;
  min-height: 44px; /* cible tactile confortable (terrain) */
  font-size: 13.5px;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all .15s;
}
.chip:hover { background: var(--blue); color: #fff; border-color: var(--blue); }
.chip::before { content: "＋"; font-weight: 800; opacity: .8; }

/* --- Listes / lignes --- */
.results, .lignes { list-style: none; margin: 10px 0 0; padding: 0; }
.results li, .lignes li {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  font-size: 14px;
}
.results li em { color: var(--green-dark); font-style: normal; font-weight: 700; }
.btn-add {
  margin-left: auto;
  background: var(--green);
  color: #fff;
  width: 30px; height: 30px;
  font-size: 18px;
  line-height: 1;
}
/* Le libellé prend toute la largeur ; les contrôles (qté, prix, total,
   suppression) passent dessous → zéro débordement même sur iPhone (393 px). */
.ligne { flex-wrap: wrap; row-gap: 6px; }
.ligne-lib { flex: 1 1 100%; min-width: 0; font-weight: 600; }
.presta-line .presta-desc { flex-basis: 100%; font-size: 11px; color: var(--muted); margin-top: 0; font-weight: 500; }
.ligne .qte { width: 56px; padding: 8px; }
.ligne .pu { width: 84px; padding: 8px; }
.ligne .montant { flex: 1; min-width: 90px; padding: 8px; font-weight: 700; }
.ligne-tot { width: 80px; text-align: right; font-weight: 700; color: var(--blue); }
.btn-del {
  background: #f7e9ea;
  color: var(--bad);
  width: 28px; height: 28px;
  font-size: 13px;
}

/* --- Totaux / rentabilité --- */
.trow { display: flex; justify-content: space-between; padding: 6px 0; font-size: 14px; }
.trow span:first-child { color: var(--muted); }
.trow--big { font-size: 17px; border-top: 1.5px solid var(--line); margin-top: 6px; padding-top: 10px; }
.trow--big strong { color: var(--green-dark); }
.totals .trow strong { color: var(--txt); }
.renta { border-left: 4px solid var(--muted); }
.renta--ok { border-left-color: var(--ok); }
.renta--warn { border-left-color: var(--warn); }
.renta--bad { border-left-color: var(--bad); }

/* --- Galerie photos --- */
.filebtn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-alt);
  color: var(--blue);
  font-weight: 700;
  padding: 14px;
  border-radius: 10px;
  cursor: pointer;
}
.gallery { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-top: 12px; }
.thumb { position: relative; margin: 0; }
.thumb img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 8px; }
.thumb .btn-del { position: absolute; top: 4px; right: 4px; }

/* --- Tabbar (bas) --- */
.tabbar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: #fff;
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  z-index: 10;
  /* barre défilante : tient n'importe quel nombre d'agents (extensions) */
  overflow-x: auto;
  scrollbar-width: none;
}
.tabbar::-webkit-scrollbar { display: none; }
.tab {
  flex: 1 0 auto;
  min-width: 64px; /* au-delà de ~6 onglets, la barre défile horizontalement */
  background: none;
  padding: 8px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
}
.tab-lb { white-space: nowrap; }
.tab-ic { font-size: 19px; filter: grayscale(1); opacity: .55; }
.tab--active { color: var(--blue); }
.tab--active .tab-ic { filter: none; opacity: 1; }

/* --- Toasts --- */
#toast-host {
  position: fixed;
  bottom: calc(90px + env(safe-area-inset-bottom)); left: 0; right: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  z-index: 50;
  pointer-events: none;
}
.toast {
  background: var(--blue-dark);
  color: #fff;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  opacity: 0;
  transform: translateY(10px);
  transition: all .25s;
  box-shadow: var(--shadow-md);
}
.toast--show { opacity: 1; transform: translateY(0); }
.toast--ok { background: var(--green-dark); }
.toast--warn { background: var(--warn); }

/* --- Copilote IA : alertes & suggestions --- */
.alertes, .suggestions {
  list-style: none; margin: 8px 0 0; padding: 0;
  display: flex; flex-direction: column; gap: 8px;
}
.alerte {
  padding: 10px 12px; border-radius: 10px; font-size: 13px;
  border-left: 4px solid var(--muted); background: var(--bg-alt);
}
.alerte strong { font-weight: 800; }
.alerte--info { border-left-color: var(--blue-light); }
.alerte--attention { border-left-color: var(--warn); background: #fdf6ec; }
.alerte--critique { border-left-color: var(--bad); background: #fbeeef; }
.suggestion {
  display: flex; flex-direction: column; gap: 2px;
  padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; font-size: 13px;
}
.suggestion strong { color: var(--blue); font-weight: 800; }
.suggestion span { color: var(--muted); }

/* --- Configurateur de tableau électrique --- */
.cfg-step-num {
  display: inline-block;
  font-size: 11px; font-weight: 800; letter-spacing: .04em;
  color: var(--green-dark); background: var(--bg-alt);
  padding: 3px 9px; border-radius: 999px; margin-bottom: 8px;
}
.cfg-radios { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.cfg-gammes { display: grid; grid-template-columns: 1fr; gap: 10px; }
.cfg-radio {
  position: relative;
  display: flex; flex-direction: column; gap: 3px;
  border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px 12px; cursor: pointer; margin: 0;
  background: #fbfcfb; transition: border-color .15s, background .15s;
}
.cfg-radio input { position: absolute; opacity: 0; width: 0; height: 0; }
.cfg-radio.checked { border-color: var(--blue); background: #eef3f8; box-shadow: 0 0 0 1.5px var(--blue) inset; }
.cfg-radio-name { font-weight: 800; color: var(--txt); font-size: 15px; }
.cfg-radio-meta { font-size: 11px; color: var(--muted); font-weight: 500; }
.cfg-gamme .cfg-gamme-desc { font-size: 12px; color: var(--muted); font-weight: 500; margin-top: 2px; }
.cfg-gamme-price { font-size: 12px; color: var(--muted); margin-top: 4px; }
.cfg-gamme-price strong { color: var(--green-dark); font-weight: 800; }

.cfg-opts { display: flex; flex-direction: column; gap: 8px; }
.cfg-opt {
  position: relative;
  display: flex; align-items: flex-start; gap: 10px;
  border: 1.5px solid var(--line); border-radius: 12px;
  padding: 12px; cursor: pointer; margin: 0;
  background: #fbfcfb; transition: border-color .15s, background .15s;
}
.cfg-opt input { position: absolute; opacity: 0; width: 0; height: 0; }
.cfg-opt.checked { border-color: var(--green); background: #eef6f0; }
.cfg-opt-icon { font-size: 22px; line-height: 1; }
.cfg-opt-body { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.cfg-opt-head { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.cfg-opt-name { font-weight: 700; color: var(--txt); font-size: 14px; }
.cfg-opt-price { font-weight: 800; color: var(--green-dark); white-space: nowrap; }
.cfg-opt-desc { font-size: 11.5px; color: var(--muted); font-weight: 500; }
#cfg-summary #cfg-toggle { margin-top: 10px; width: 100%; }

/* --- Sourcing matériels --- */
.src-items { list-style: none; margin: 8px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.src-item { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.src-item-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.src-item-top strong { color: var(--txt); font-size: 14px; }
.src-moy { font-weight: 800; color: var(--green-dark); white-space: nowrap; }
.src-desc { font-size: 12px; color: var(--muted); margin: 4px 0; }
.src-links { font-size: 12px; }
.src-links a { color: var(--blue); font-weight: 700; text-decoration: none; }
.src-links a:hover { text-decoration: underline; }

@media (min-width: 640px) {
  .panels { max-width: 620px; margin: 0 auto; width: 100%; }
  .tabbar { max-width: 620px; margin: 0 auto; }
  /* barre d'app : contenu aligné sur la colonne centrale (MacBook Air) */
  .appbar-title { max-width: 620px; margin: 0 auto; }
}
