/* === Réinitialisation & variables === */
:root {
  --vert: #C3D984;
  --vert-fonce: #8FA84A;
  --rose: #EF7580;
  --rose-fonce: #D9596A;
  --rose-clair: #FCC8BE;
  --gris: #F5F5F5;
  --gris-bord: #E0E0E0;
  --gris-fonce: #A0A0A0;
  --texte: #3A3A3A;
  --texte-gris: #777777;
}

* { box-sizing: border-box; }

body {
  font-family: system-ui, -apple-system, sans-serif;
  color: var(--texte);
  background: var(--gris);
}

/* === Boutons === */
.btn-primary {
  background: var(--vert);
  color: var(--texte);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-primary:hover {
  background: var(--vert-fonce);
}
.btn-secondary {
  background: var(--gris-bord);
  color: var(--texte);
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.btn-secondary:hover {
  background: var(--gris-fonce);
  color: white;
}
.btn-rose {
  background: var(--rose);
  color: white;
  padding: 0.5rem 1rem;
  border-radius: 0.5rem;
  font-weight: 600;
  font-size: 0.875rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
}
.btn-rose:hover {
  background: var(--rose-fonce);
}
.btn-add {
  background: var(--vert);
  color: var(--texte);
  border: 2px solid var(--vert-fonce);
  padding: 0.45rem 0.85rem;
  border-radius: 0.5rem;
  font-size: 0.8125rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  transition: background 0.15s, box-shadow 0.15s, transform 0.1s;
}
.btn-add:hover {
  background: var(--vert-fonce);
  color: white;
  box-shadow: 0 4px 10px rgba(0,0,0,0.20);
  transform: translateY(-1px);
}
.btn-add:active {
  transform: translateY(0);
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
}
.btn-danger {
  color: white;
  padding: 0.25rem 0.75rem;
  border-radius: 0.25rem;
  font-size: 0.75rem;
  border: none;
  cursor: pointer;
  transition: background 0.15s;
  background: #E0504F;
}
.btn-danger:hover {
  background: #C73E3D;
}

/* === Onglets === */
.tab-btn {
  background: var(--gris);
  color: var(--texte-gris);
  border: 1px solid var(--gris-bord);
  border-bottom: 0;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.tab-btn.active {
  background: var(--vert);
  color: var(--texte);
  border-color: var(--vert);
  font-weight: 700;
}
.tab-content {
  display: block;
}
.tab-content.hidden {
  display: none;
}

/* === Formulaires === */
input[type="text"],
input[type="email"],
input[type="tel"],
input[type="date"],
input[type="time"],
input[type="number"],
select {
  border: 1px solid var(--gris-bord);
  border-radius: 0.25rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}
input:focus,
select:focus {
  outline: none;
  border-color: var(--vert);
  box-shadow: 0 0 0 2px var(--vert);
}

/* Restaurer l'apparence native des cases à cocher et boutons radio
   (Tailwind Preflight les masque avec appearance:none) */
input[type="checkbox"],
input[type="radio"] {
  appearance: auto;
  -webkit-appearance: auto;
  width: 1rem;
  height: 1rem;
  cursor: pointer;
  border: none;
  padding: 0;
  accent-color: var(--vert-fonce);
}

.input-modal {
  width: 100%;
  border: 1px solid var(--gris-bord);
  border-radius: 0.25rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
}

/* === Modales === */
.modal {
  display: flex;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  align-items: center;
  justify-content: center;
  z-index: 9999;
}
.modal.hidden {
  display: none;
}
.modal-content {
  background: white;
  border-radius: 0.5rem;
  padding: 1.5rem;
  max-width: 28rem;
  width: 90%;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1);
}

/* === Tableau === */
table {
  width: 100%;
  border-collapse: collapse;
}
tbody tr {
  border-bottom: 1px solid var(--gris-bord);
  transition: background 0.15s;
}
tbody tr:hover {
  background: #FBF1EF;
}
/* Lignes regroupées : grisées sur toute leur longueur (montants compris) ;
   les champs restent modifiables (la modification met à jour l'en-tête de groupe). */
tbody tr.ligne-groupee {
  background: #F1F1F1;
  color: #9a9a9a;
}
tbody tr.ligne-groupee:hover {
  background: #ECECEC;
}
tbody tr.ligne-groupee input,
tbody tr.ligne-groupee select {
  opacity: 0.65;
}
tbody input,
tbody select {
  width: 100%;
  border: 1px solid var(--gris-bord);
  border-radius: 0.25rem;
  padding: 0.25rem 0.5rem;
  font-size: 0.75rem;
}

/* === Grille produits === */
#produits-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}
.produit-card {
  background: white;
  border-radius: 0.5rem;
  overflow: hidden;
  border: 1px solid var(--gris-bord);
  padding: 0.75rem;
  cursor: pointer;
  transition: box-shadow 0.2s;
  display: flex;
  flex-direction: column;
}
.produit-card:hover { box-shadow: 0 10px 15px -3px rgba(0,0,0,0.15); }
.produit-card.selected { border: 2px solid var(--vert); }
.produit-image {
  width: 100%;
  height: 7rem;
  border-radius: 0.375rem;
  margin-bottom: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 2.75rem;
}
.produit-name {
  font-weight: 700;
  font-size: 0.75rem;
  margin-bottom: 0.15rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  line-height: 1.3;
}
.produit-detail {
  font-size: 0.7rem;
  color: var(--texte-gris);
  margin-bottom: 0.1rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.produit-footer {
  margin-top: auto;
  padding-top: 0.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.25rem;
  flex-wrap: wrap;
  row-gap: 0.35rem;
}
.produit-prix {
  font-weight: 700;
  color: var(--vert-fonce);
  font-size: 0.8rem;
  white-space: nowrap;
}
.produit-prix-input {
  width: 101px;
  font-weight: 700;
  color: var(--vert-fonce);
  font-size: 0.8rem;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 1px 3px;
  background: transparent;
  text-align: right;
  cursor: text;
}
.produit-prix-input:hover,
.produit-prix-input:focus {
  border-color: var(--vert-fonce);
  background: white;
  outline: none;
}
/* Zone prix : champ + sigle € + bouton « Mém » accolés à droite */
.produit-prix-edit {
  display: flex;
  align-items: center;
  gap: 3px;
}
.produit-prix-euro {
  font-weight: 700;
  color: var(--vert-fonce);
  font-size: 0.8rem;
  line-height: 1;
}
/* Bouton poubelle « Suppr » d'une vignette */
.produit-suppr-btn {
  background: transparent;
  border: none;
  cursor: pointer;
  font-size: 0.85rem;
  line-height: 1;
  padding: 2px 3px;
  opacity: 0.55;
  transition: opacity 0.15s, transform 0.1s;
}
.produit-suppr-btn:hover {
  opacity: 1;
  transform: scale(1.15);
}
.produit-mem-btn {
  background: var(--vert);
  color: var(--texte);
  border: 1px solid var(--vert-fonce);
  border-radius: 5px;
  padding: 2px 5px;
  font-size: 0.62rem;
  font-weight: 700;
  line-height: 1;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s, color 0.15s;
}
.produit-mem-btn:hover {
  background: var(--vert-fonce);
  color: white;
}

/* === Pop-up flash furtif (confirmation « OK ») === */
.flash-ok {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: var(--vert-fonce);
  color: white;
  padding: 0.9rem 2.2rem;
  border-radius: 0.75rem;
  font-size: 1.6rem;
  font-weight: 700;
  z-index: 10000;
  pointer-events: none;
  opacity: 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.25);
}
.flash-ok.show {
  animation: flashOk 1s ease forwards;
}
@keyframes flashOk {
  0%   { opacity: 0; }
  30%  { opacity: 0.8; }
  70%  { opacity: 0.8; }
  100% { opacity: 0; }
}
.produit-qte-add {
  display: flex;
  align-items: center;
  gap: 3px;
}
.produit-qte-add input {
  width: 40px;
  font-size: 12px;
  border: 1px solid var(--gris-bord);
  border-radius: 4px;
  padding: 2px 4px;
  text-align: center;
}
.produit-qte-add button {
  background: var(--vert);
  border: none;
  border-radius: 6px;
  padding: 3px 9px;
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  line-height: 1;
  color: var(--texte);
  transition: background 0.15s;
}
.produit-qte-add button:hover { background: var(--vert-fonce); }

/* === Bouton surélevé (en-tête devis) === */
.btn-action {
  background: white;
  border: 2px solid var(--vert-fonce);
  box-shadow: 0 3px 6px rgba(0,0,0,0.18), 0 1px 2px rgba(0,0,0,0.10);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.4rem 0.9rem;
  border-radius: 0.5rem;
  cursor: pointer;
  color: var(--vert-fonce);
  transition: box-shadow 0.15s, transform 0.1s;
  width: 100%;
  text-align: center;
}
.btn-action:hover {
  box-shadow: 0 5px 14px rgba(0,0,0,0.22);
  transform: translateY(-1px);
}
.btn-action:active {
  box-shadow: 0 1px 3px rgba(0,0,0,0.12);
  transform: translateY(0);
}

/* === Utilitaires === */
.text-vert { color: var(--vert); }
.text-rose { color: var(--rose); }
.text-texte-gris { color: var(--texte-gris); }
.text-danger { color: #E0504F; transition: color 0.15s; }
.text-danger:hover { color: #C73E3D; }
.bg-totaux { background-color: #F4F8E9; color: var(--texte); }
/* La pastille TTC reste en texte blanc sur fond rose, quel que soit le thème */
.bg-totaux .bg-rose { color: #fff; }

/* === Dropdown recherche produit === */
#search-produit-dropdown {
  background-color: white;
}

/* === Grille Clients / Événements === */
.clients-evt-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
  align-items: start;
}

.cards-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 60vh;
  overflow-y: auto;
}

/* Champs à l'intérieur d'une carte : 2 colonnes sur bureau, 1 sur mobile */
.card-fields {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.15rem 0.75rem;
  margin-top: 0.25rem;
}

/* === Responsive === */
@media (max-width: 900px) {
  #produits-grid { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  #produits-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .clients-evt-grid { grid-template-columns: 1fr; }
  .card-fields      { grid-template-columns: 1fr; }
}

/* === Estimation : % par catégorie + curseur (boîte élargie, alignement par grille) === */
.est-cat-pct-input {
  width: 3.4rem;
  padding: 0.15rem 0.2rem;
  text-align: right;
  background: transparent;
  border: none;
  font-size: 0.875rem;
  -moz-appearance: textfield;
}
.est-cat-pct-input::-webkit-outer-spin-button,
.est-cat-pct-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
/* Case Montant (calculée ou saisie pour Transports/Personnel) : plus large pour accueillir
   4 chiffres (jusqu'à 9999) sans coupure. */
.est-cat-montant-input {
  width: 4.4rem;
  padding: 0.15rem 0.2rem;
  text-align: right;
  background: transparent;
  border: none;
  font-size: 0.875rem;
  -moz-appearance: textfield;
}
.est-cat-montant-input::-webkit-outer-spin-button,
.est-cat-montant-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
.est-cat-range {
  width: 100%;
  cursor: pointer;
  accent-color: currentColor;
}
/* Largeur fixe du suffixe (%/€) : « € » et « % » n'ont pas la même largeur de glyphe,
   ce qui décalait sinon la boîte de quelques pixels d'une barre à l'autre. */
.est-cat-suffix {
  display: inline-block;
  width: 0.85em;
  text-align: left;
}

/* === Thème sombre (si nécessaire) === */
body.dark-mode {
  background: #2A2A2A;
  color: white;
}
body.dark-mode .bg-white {
  background: #383838;
}
body.dark-mode .border-gris-bord {
  border-color: #4A4A4A;
}
/* Champs de saisie lisibles en mode sombre (sinon texte blanc sur fond blanc) */
body.dark-mode input[type="text"],
body.dark-mode input[type="email"],
body.dark-mode input[type="tel"],
body.dark-mode input[type="date"],
body.dark-mode input[type="time"],
body.dark-mode input[type="number"],
body.dark-mode select,
body.dark-mode textarea,
body.dark-mode .input-modal {
  background: #383838;
  color: #fff;
  border-color: #4A4A4A;
}
body.dark-mode select option {
  background: #383838;
  color: #fff;
}
body.dark-mode input::placeholder,
body.dark-mode textarea::placeholder {
  color: #B0B0B0;
}
