/* ============================================================
 * app.css — UI mobile-first "Devis Mobile"
 * 100% autonome, aucune dépendance externe.
 * ============================================================ */

:root {
  --bleu: #1a3c6e;
  --bleu-clair: #2b5aa0;
  --bleu-pale: #eaf0f9;
  --vert: #1e7e34;
  --vert-pale: #e6f4ea;
  --orange: #b26a00;
  --orange-pale: #fdf1dc;
  --rouge: #b3261e;
  --rouge-pale: #fbe9e7;
  --gris: #5f6b7a;
  --gris-clair: #eef1f5;
  --bord: #d5dce6;
  --fond: #f4f6f9;
  --blanc: #ffffff;
  --texte: #1c2330;
  --rayon: 12px;
  --ombre: 0 1px 3px rgba(20, 30, 50, 0.08);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--fond);
  color: var(--texte);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  font-size: 16px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 16px; }

/* ---------- Header ---------- */
.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: var(--bleu);
  color: #fff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.18);
}
.app-header h1 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
  letter-spacing: 0.2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.icon-btn {
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  font-size: 22px;
  line-height: 1;
  display: flex;
  align-items: center;
  justify-content: center;
}
.icon-btn:active { background: rgba(255, 255, 255, 0.3); }

/* ---------- Main ---------- */
.app-main {
  max-width: 720px;
  margin: 0 auto;
  padding: 12px 12px 90px;
}

.vue-titre { font-size: 14px; color: var(--gris); margin: 4px 0 12px; }

/* ---------- Cartes ---------- */
.carte {
  background: var(--blanc);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 14px;
  margin-bottom: 12px;
}
.carte h2, .carte h3 { margin: 0 0 10px; font-size: 16px; }

/* ---------- Grille KPIs accueil ---------- */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.kpi {
  background: var(--blanc);
  border: 1px solid var(--bord);
  border-radius: var(--rayon);
  box-shadow: var(--ombre);
  padding: 12px;
  text-align: center;
}
.kpi .kpi-valeur { font-size: 22px; font-weight: 800; color: var(--bleu); }
.kpi .kpi-label { font-size: 12px; color: var(--gris); margin-top: 2px; }

.raccourcis { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.raccourci {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 16px 8px;
  background: var(--bleu-pale);
  color: var(--bleu);
  border: 1px solid transparent;
  border-radius: var(--rayon);
  font-weight: 700;
  font-size: 14px;
}
.raccourci .nav-icone { font-size: 26px; }
.raccourci:active { border-color: var(--bleu-clair); }

/* ---------- Listes ---------- */
.liste { list-style: none; margin: 0; padding: 0; }
.liste-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--gris-clair);
}
.liste-item:last-child { border-bottom: 0; }
.liste-item .corps { flex: 1; min-width: 0; }
.liste-item .titre-ligne { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.liste-item .sous-ligne { font-size: 12.5px; color: var(--gris); margin-top: 1px; }
.liste-item .montant { font-weight: 700; font-size: 14px; white-space: nowrap; }
.liste-actions { display: flex; gap: 6px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.2px;
}
.badge-devis  { background: var(--bleu-pale);  color: var(--bleu); }
.badge-bc     { background: var(--vert-pale);  color: var(--vert); }
.badge-bl     { background: var(--orange-pale); color: var(--orange); }
.badge-facture{ background: var(--rouge-pale); color: var(--rouge); }
.badge-soldee { background: var(--vert-pale);  color: var(--vert); }
.badge-partiel{ background: var(--orange-pale); color: var(--orange); }
.badge-info   { background: var(--bleu-pale);  color: var(--bleu); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 11px 16px;
  border: 1px solid var(--bord);
  border-radius: 10px;
  background: var(--blanc);
  color: var(--texte);
  font-size: 15px;
  font-weight: 600;
  min-height: 44px;
}
.btn:active { background: var(--gris-clair); }
.btn-primaire { background: var(--bleu); border-color: var(--bleu); color: #fff; }
.btn-primaire:active { background: var(--bleu-clair); }
.btn-danger { color: var(--rouge); border-color: #f0c6c2; }
.btn-danger:active { background: var(--rouge-pale); }
.btn-petit { padding: 7px 10px; font-size: 13px; min-height: 34px; border-radius: 8px; }
.btn-bloc { width: 100%; margin-top: 4px; }
.btn-groupe { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.btn-groupe .btn { flex: 1; min-width: 110px; }

/* ---------- Formulaires ---------- */
.champ { margin-bottom: 12px; }
.champ label { display: block; font-size: 13px; font-weight: 600; color: var(--gris); margin-bottom: 4px; }
.champ input[type="text"],
.champ input[type="number"],
.champ input[type="date"],
.champ input[type="tel"],
.champ input[type="email"],
.champ select,
.champ textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--bord);
  border-radius: 10px;
  background: var(--blanc);
  color: var(--texte);
  min-height: 44px;
}
.champ textarea { resize: vertical; min-height: 72px; }
.champ input:focus, .champ select:focus, .champ textarea:focus {
  outline: none;
  border-color: var(--bleu-clair);
  box-shadow: 0 0 0 3px rgba(43, 90, 160, 0.15);
}
.champ-ligne { display: flex; gap: 10px; }
.champ-ligne > * { flex: 1; }
.champ-hint { font-size: 12px; color: var(--gris); margin-top: 3px; }

/* Cases à cocher (switch) */
.switch-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; }
.switch-row label { font-size: 15px; font-weight: 500; }
.switch-row input[type="checkbox"] { width: 22px; height: 22px; accent-color: var(--bleu); }

/* ---------- Éditeur de lignes ---------- */
.lignes-editor { margin-top: 6px; }
.ligne-row {
  border: 1px solid var(--bord);
  border-radius: 10px;
  padding: 10px;
  margin-bottom: 8px;
  background: #fbfcfe;
}
.ligne-row .ligne-desc { width: 100%; margin-bottom: 6px; }
.ligne-row .ligne-grid {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr auto;
  gap: 6px;
  align-items: center;
}
.ligne-row input { padding: 9px 8px; border: 1px solid var(--bord); border-radius: 8px; font-size: 15px; }
.ligne-row input.num { text-align: right; }
.ligne-row .ligne-total { font-size: 13px; font-weight: 700; color: var(--gris); text-align: right; padding-right: 2px; }
.ligne-suppr {
  border: 0;
  background: transparent;
  color: var(--rouge);
  font-size: 20px;
  line-height: 1;
  padding: 4px 6px;
}

/* ---------- Totaux (éditeur) ---------- */
.totaux-resume {
  background: var(--gris-clair);
  border-radius: 10px;
  padding: 12px;
  margin-top: 8px;
}
.totaux-resume .row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 14px; }
.totaux-resume .row.net { border-top: 2px solid var(--bleu); margin-top: 6px; padding-top: 8px; font-weight: 800; font-size: 16px; color: var(--bleu); }
.totaux-resume .row.neg { color: var(--rouge); }

/* ---------- Détail document ---------- */
.detail-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.detail-head h2 { margin: 0; flex: 1; font-size: 18px; }
.btn-retour {
  border: 1px solid var(--bord);
  background: var(--blanc);
  border-radius: 10px;
  min-height: 40px;
  padding: 0 12px;
  font-size: 18px;
}
.table-suivi { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.table-suivi th, .table-suivi td { border: 1px solid var(--bord); padding: 6px 8px; text-align: right; }
.table-suivi th { background: var(--gris-clair); text-align: left; font-size: 11.5px; }
.table-suivi td.desc { text-align: left; }
.table-suivi td:first-child, .table-suivi th:first-child { text-align: left; }

/* ---------- Filtres ---------- */
.filtres { display: flex; gap: 8px; margin-bottom: 12px; }
.filtres .puce {
  flex: 1;
  padding: 8px 4px;
  border: 1px solid var(--bord);
  border-radius: 999px;
  background: var(--blanc);
  font-size: 12.5px;
  font-weight: 600;
  color: var(--gris);
  text-align: center;
}
.filtres .puce.is-active { background: var(--bleu); color: #fff; border-color: var(--bleu); }
.recherche { width: 100%; margin-bottom: 12px; }

/* ---------- Nav basse ---------- */
.app-nav {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 40;
  display: flex;
  background: var(--blanc);
  border-top: 1px solid var(--bord);
  box-shadow: 0 -2px 8px rgba(20, 30, 50, 0.08);
  padding-bottom: env(safe-area-inset-bottom);
}
.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 8px 2px 6px;
  border: 0;
  background: transparent;
  color: var(--gris);
  font-size: 11px;
  font-weight: 600;
}
.nav-btn .nav-icone { font-size: 20px; line-height: 1; }
.nav-btn.is-active { color: var(--bleu); }
.nav-btn-central .nav-icone-plus {
  width: 46px;
  height: 46px;
  margin-top: -18px;
  border-radius: 50%;
  background: var(--bleu);
  color: #fff;
  font-size: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(26, 60, 110, 0.35);
}

/* ---------- Modal ---------- */
.modal-masque {
  position: fixed;
  inset: 0;
  background: rgba(15, 22, 36, 0.5);
  z-index: 50;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.modal-carte {
  background: var(--blanc);
  border-radius: 16px 16px 0 0;
  width: 100%;
  max-width: 720px;
  max-height: 86vh;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.modal-carte h3 { margin: 0 0 12px; font-size: 17px; }
.modal-actions { display: flex; gap: 8px; margin-top: 14px; }
.modal-actions .btn { flex: 1; }

/* ---------- Toast ---------- */
.toast-root {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translateX(-50%);
  z-index: 60;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  background: #232a35;
  color: #fff;
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 14px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
  animation: toast-in 0.18s ease-out;
  max-width: 88vw;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.vide { text-align: center; color: var(--gris); padding: 28px 10px; font-size: 14px; }

@media (min-width: 720px) {
  .app-nav { left: 50%; right: auto; transform: translateX(-50%); width: 720px; border-radius: 14px 14px 0 0; }
  .kpi-grid { grid-template-columns: repeat(4, 1fr); }
}
