:root {
  --fond: #f5f4f0;
  --surface: #ffffff;
  --surface-2: #f0efea;
  --texte: #1c1b19;
  --texte-doux: #6b6962;
  --trait: #e2e0d9;
  --trait-fort: #c9c6bd;
  --accent: #1c1b19;
  --accent-texte: #ffffff;
  /* Répartition du HT (palette validée : CVD et contraste) */
  --serie-net: #2a78d6;
  --serie-urssaf: #1baf7a;
  --serie-tresorerie: #eb6834;
  --focus: #2f5bd3;
  --erreur: #c0392b;
  --ombre: 0 1px 2px rgb(0 0 0 / 0.04), 0 2px 8px rgb(0 0 0 / 0.04);
  --rayon: 10px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --fond: #151513;
    --surface: #1e1e1b;
    --surface-2: #262623;
    --texte: #ecebe6;
    --texte-doux: #9d9b93;
    --trait: #33322e;
    --trait-fort: #4a4943;
    --accent: #ecebe6;
    --accent-texte: #151513;
    --serie-net: #3987e5;
    --serie-urssaf: #199e70;
    --serie-tresorerie: #d95926;
    --focus: #7c9cf2;
    --erreur: #ef7564;
    --ombre: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
}

h2 { font-size: 15px; font-weight: 600; margin: 0; }
button, input, select { font: inherit; color: inherit; }
[hidden] { display: none !important; }

.num, .montant, .item-meta, .tableau-recap, .totaux { font-variant-numeric: tabular-nums; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* ---------- Barre ---------- */

.barre {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--trait);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 5;
}
.marque { font-size: 15px; white-space: nowrap; }
.marque strong { font-weight: 700; letter-spacing: -0.01em; }
.marque span { color: var(--texte-doux); margin-left: 4px; }

.onglets { display: flex; gap: 4px; }
.onglet {
  border: 0;
  background: none;
  padding: 6px 12px;
  border-radius: 999px;
  color: var(--texte-doux);
  cursor: pointer;
}
.onglet:hover { color: var(--texte); }
.onglet.actif { background: var(--surface-2); color: var(--texte); font-weight: 600; }

.alerte {
  margin: 16px 24px 0;
  padding: 10px 14px;
  border-radius: var(--rayon);
  border: 1px solid var(--erreur);
  color: var(--erreur);
  background: var(--surface);
}

main { max-width: 1320px; margin: 0 auto; padding: 24px; }

/* ---------- Boutons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--trait-fort);
  border-radius: 8px;
  background: var(--surface);
  cursor: pointer;
  white-space: nowrap;
}
.btn:hover { border-color: var(--texte-doux); }
.btn-petit { padding: 5px 11px; font-size: 14px; }
.btn-discret { border-color: transparent; background: none; color: var(--texte-doux); }
.btn-discret:hover { color: var(--texte); border-color: var(--trait); }
.btn-principal { background: var(--accent); color: var(--accent-texte); border-color: var(--accent); }
.btn-principal:hover { opacity: 0.88; border-color: var(--accent); }

.btn-icone {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 6px;
  background: none;
  color: var(--texte-doux);
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
}
.btn-icone:hover { background: var(--surface-2); color: var(--erreur); }

/* ---------- Champs ---------- */

input:not([type]), input[type="text"], select {
  width: 100%;
  min-width: 0;
  padding: 7px 10px;
  border: 1px solid var(--trait);
  border-radius: 7px;
  background: var(--surface);
}
input:hover, select:hover { border-color: var(--trait-fort); }
input:focus, select:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--focus) 20%, transparent); }
input::placeholder { color: var(--texte-doux); opacity: 0.6; }
input.num { text-align: right; }
input.invalide { border-color: var(--erreur); }

.champ-unite { position: relative; display: block; }
.champ-unite input { padding-right: 26px; }
.champ-unite > span {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--texte-doux);
  pointer-events: none;
}
.champ-fort input { font-weight: 600; }

.etiquette { display: block; font-size: 12px; color: var(--texte-doux); margin-bottom: 4px; }
.etiquette-mobile {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.aide { color: var(--texte-doux); font-size: 13px; margin: 10px 0 0; max-width: 72ch; }

/* ---------- Mise en page devis ---------- */

.vue-devis {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 24px;
  align-items: start;
}

.liste-devis { position: sticky; top: 78px; }
.liste-entete { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
#liste-devis { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; max-height: calc(100vh - 140px); overflow: auto; }

.item-devis {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: none;
  border-radius: 8px;
  padding: 8px 10px;
  cursor: pointer;
  display: grid;
  gap: 2px;
}
.item-devis:hover { background: var(--surface-2); }
.item-devis.actif { background: var(--surface); border-color: var(--trait); box-shadow: var(--ombre); }
.item-nom { font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--texte-doux); }

.editeur {
  background: var(--surface);
  border: 1px solid var(--trait);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--ombre);
  min-width: 0;
}

.entete-devis { display: flex; gap: 16px; align-items: center; }
.champ-titre {
  font-size: 22px !important;
  font-weight: 600;
  letter-spacing: -0.01em;
  border-color: transparent !important;
  padding: 4px 8px !important;
  margin-left: -8px;
}
.champ-titre:hover { border-color: var(--trait) !important; }
.champ-titre:focus { border-color: var(--focus) !important; }
.actions-devis { display: flex; gap: 6px; flex-shrink: 0; }

.reglages { display: flex; flex-wrap: wrap; gap: 16px 20px; margin-top: 20px; align-items: flex-end; }
.reglage { display: block; min-width: 170px; }
.reglage-court { min-width: 0; width: 96px; }

.segments { display: inline-flex; padding: 3px; gap: 2px; background: var(--surface-2); border-radius: 9px; }
.segments button {
  border: 0;
  background: none;
  padding: 5px 12px;
  border-radius: 7px;
  cursor: pointer;
  color: var(--texte-doux);
  white-space: nowrap;
}
.segments button[aria-checked="true"] { background: var(--surface); color: var(--texte); font-weight: 600; box-shadow: var(--ombre); }

/* ---------- Lignes ---------- */

.lignes { margin-top: 22px; border-top: 1px solid var(--trait); }

.ligne {
  display: grid;
  grid-template-columns: 150px minmax(120px, 1fr) 130px 104px 150px 30px;
  gap: 10px;
  align-items: start;
  padding: 10px 0;
  border-bottom: 1px solid var(--trait);
}
.mode-inverse .ligne { grid-template-columns: 150px minmax(120px, 1fr) 80px 104px 130px 130px 30px; }

.ligne-entete { font-size: 12px; color: var(--texte-doux); padding: 8px 0; align-items: end; }
.ligne-entete span:nth-child(n+3) { text-align: right; }

.cellule { display: block; min-width: 0; }
.c-calc { text-align: right; padding-top: 4px; display: grid; justify-items: end; }
.c-calc small { font-size: 12px; color: var(--texte-doux); }
.c-taux { display: grid; justify-items: end; gap: 2px; }

.lien-taux {
  border: 0;
  background: none;
  padding: 0;
  font-size: 11.5px;
  color: var(--focus);
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.montant {
  border: 0;
  background: none;
  padding: 1px 4px;
  margin: -1px -4px;
  border-radius: 5px;
  cursor: copy;
  text-align: right;
}
.montant:hover { background: var(--surface-2); }
.montant-fort { font-weight: 600; }

.lignes-actions { display: flex; gap: 8px; margin-top: 12px; }

/* ---------- Récapitulatif ---------- */

.recap { margin-top: 32px; padding-top: 24px; border-top: 1px solid var(--trait); }
.recap-entete { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 14px; }
.recap-entete h2 { font-size: 17px; }

.tableau-defilant { overflow-x: auto; }
.tableau-recap { width: 100%; border-collapse: collapse; }
.tableau-recap th, .tableau-recap td { padding: 9px 10px; border-bottom: 1px solid var(--trait); text-align: right; white-space: nowrap; }
.tableau-recap th:first-child { text-align: left; padding-left: 0; font-weight: 500; }
.tableau-recap thead th { font-size: 12px; font-weight: 400; color: var(--texte-doux); }
.tableau-recap tfoot th, .tableau-recap tfoot td { border-bottom: 0; border-top: 1px solid var(--trait-fort); font-weight: 600; }
.nul { color: var(--texte-doux); }

.badge {
  display: inline-block;
  font-size: 11px;
  font-weight: 500;
  padding: 1px 7px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--texte-doux);
  margin-left: 4px;
  vertical-align: 1px;
}

.totaux {
  margin: 20px 0 0 auto;
  max-width: 340px;
  display: grid;
  gap: 2px;
}
.totaux > div { display: flex; justify-content: space-between; gap: 16px; padding: 5px 0; }
.totaux dt { color: var(--texte-doux); }
.totaux dd { margin: 0; }
.totaux .total-fort { border-top: 1px solid var(--trait-fort); padding-top: 9px; margin-top: 4px; font-size: 18px; font-weight: 700; }
.totaux .total-fort dt { color: var(--texte); }
.aide-recap { text-align: right; max-width: none; }

.avertissement {
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--texte-doux);
  margin: 0 0 12px;
}
.vide { color: var(--texte-doux); }

/* ---------- Collaborateurs ---------- */

.vue-collaborateurs { display: grid; gap: 24px; max-width: 820px; }
.panneau {
  background: var(--surface);
  border: 1px solid var(--trait);
  border-radius: 14px;
  padding: 24px;
  box-shadow: var(--ombre);
}
.section-entete { display: flex; justify-content: space-between; align-items: center; }
.panneau h2 { font-size: 17px; }
.collabs { margin-top: 18px; border-top: 1px solid var(--trait); }
.collab {
  display: grid;
  grid-template-columns: minmax(110px, 1fr) 160px 84px 84px 52px 72px 30px;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--trait);
}
.collab-entete { font-size: 12px; color: var(--texte-doux); padding: 8px 0; }
.usage { font-size: 13px; color: var(--texte-doux); text-align: right; }
.collab-entete span:nth-child(n+3) { text-align: right; }
.total-taux { text-align: right; font-weight: 600; }
.boutons { display: flex; gap: 8px; margin-top: 14px; }

/* ---------- Toast ---------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translate(-50%, 12px);
  background: var(--accent);
  color: var(--accent-texte);
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s, transform 0.15s;
  z-index: 10;
}
.toast.visible { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Écrans étroits ---------- */

@media (max-width: 1080px) {
  .ligne { grid-template-columns: 130px minmax(100px, 1fr) 120px 96px 130px 30px; }
  .mode-inverse .ligne { grid-template-columns: 130px minmax(100px, 1fr) 70px 96px 120px 120px 30px; }
}

@media (max-width: 860px) {
  main { padding: 16px; }
  .barre { padding: 10px 16px; }
  .marque span { display: none; }
  .vue-devis { grid-template-columns: minmax(0, 1fr); gap: 16px; }
  .liste-devis { position: static; }
  #liste-devis { max-height: 200px; }
  .editeur, .panneau { padding: 16px; border-radius: 12px; }

  /* Les lignes deviennent des cartes */
  .ligne-entete { display: none; }
  .ligne, .mode-inverse .ligne {
    grid-template-columns: 1fr 1fr;
    grid-template-areas:
      "collab suppr"
      "desc desc"
      "saisie taux"
      "calc calc2";
    gap: 8px 12px;
    padding: 14px 0;
    position: relative;
  }
  .ligne { grid-template-areas: "collab suppr" "desc desc" "saisie taux" "calc calc"; }
  .mode-inverse .ligne { grid-template-areas: "collab suppr" "desc desc" "saisie taux" "calc calc2"; }
  .c-collab { grid-area: collab; }
  .c-desc { grid-area: desc; }
  .c-saisie { grid-area: saisie; }
  .c-taux { grid-area: taux; justify-items: stretch; }
  .c-calc { grid-area: calc; }
  .c-calc + .c-calc { grid-area: calc2; }
  .ligne .btn-icone { grid-area: suppr; justify-self: end; }
  .etiquette-mobile {
    position: static;
    width: auto; height: auto;
    overflow: visible;
    clip: auto;
    display: block;
    font-size: 12px;
    color: var(--texte-doux);
    margin-bottom: 3px;
  }
  .c-calc { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; justify-items: start; text-align: left; }
  .lien-taux { justify-self: end; }

  .entete-devis { flex-wrap: wrap; }
  .champ-titre { margin-left: 0; }
  .reglage { min-width: 0; flex: 1 1 100%; }
  .reglage-court { flex: 0 0 96px; }
  .reglages .reglage:nth-child(2) { flex: 1 1 0; }
  .segments { display: flex; }
  .segments button { flex: 1; padding: 6px 8px; }

  .recap-entete { flex-wrap: wrap; }
  .totaux { max-width: none; }

  .collab { grid-template-columns: 1fr 1fr 64px; grid-template-areas: "nom nom suppr" "type type type" "urssaf tresorerie total"; }
  .collab > label:nth-child(1) { grid-area: nom; }
  .collab > label:nth-child(2) { grid-area: type; }
  .collab > label:nth-child(3) { grid-area: urssaf; }
  .collab > label:nth-child(4) { grid-area: tresorerie; }
  .collab .total-taux { grid-area: total; align-self: end; padding-bottom: 8px; }
  .collab .usage { display: none; }
  .collab .btn-icone { grid-area: suppr; justify-self: end; }
  .collab-entete { display: none; }
}

/* ---------- Répartition du HT ---------- */

.barre-empilee {
  display: flex;
  gap: 2px; /* écart couleur de fond entre segments */
  width: 100%;
  height: 6px;
  margin: 5px 0 3px;
}
.barre-empilee .seg { flex: 0 1 0; min-width: 3px; border-radius: 2px; }
.barre-empilee .seg:first-child { border-radius: 4px 2px 2px 4px; }
.barre-empilee .seg:last-child { border-radius: 2px 4px 4px 2px; }
.barre-empilee .seg:only-child { border-radius: 4px; }
.c-calc .barre-empilee { width: 120px; max-width: 100%; }
.barre-ligne { max-width: 180px; height: 4px; margin-bottom: 0; }
.barre-grande { height: 14px; margin: 10px 0 12px; }
.barre-grande .seg { border-radius: 3px; }
.barre-grande .seg:first-child { border-radius: 7px 3px 3px 7px; }
.barre-grande .seg:last-child { border-radius: 3px 7px 7px 3px; }
.barre-grande .seg:only-child { border-radius: 7px; }

.seg-net { background: var(--serie-net); }
.seg-urssaf { background: var(--serie-urssaf); }
.seg-tresorerie { background: var(--serie-tresorerie); }

.pastille {
  display: inline-block;
  width: 9px;
  height: 9px;
  border-radius: 3px;
  margin-right: 6px;
  vertical-align: 0;
}

.repartition {
  margin: 0 0 20px;
  padding: 16px 18px;
  border: 1px solid var(--trait);
  border-radius: var(--rayon);
}
.repartition-titre { display: flex; justify-content: space-between; gap: 12px; font-weight: 600; }
.legende {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px 20px;
}
.legende li { display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 0; }
.legende .pastille { grid-row: 1; }
.legende-libelle { color: var(--texte-doux); font-size: 13px; }
.legende-valeur { grid-column: 2; font-weight: 600; justify-self: start; }
.legende-pct { grid-column: 2; font-size: 12px; color: var(--texte-doux); font-variant-numeric: tabular-nums; }

.tableau-recap thead .pastille { width: 8px; height: 8px; margin-right: 5px; }
.tableau-recap tbody th { white-space: normal; }
.totaux .total-detail dt small { display: block; font-size: 12px; }
.collab-entete .pastille { width: 8px; height: 8px; margin-right: 5px; }

@media (max-width: 860px) {
  .legende { grid-template-columns: minmax(0, 1fr); }
  .legende li { grid-template-columns: auto 1fr auto auto; column-gap: 10px; }
  .legende .pastille { margin-right: 0; }
  .legende-valeur, .legende-pct { grid-column: auto; }
  .repartition { padding: 14px; }
}
