/* ── Variables ──────────────────────────────────────────────────────────── */
:root {
  --bleu: #1B3A6B;
  --bleu-clair: #D4E1F7;
  --bleu-moyen: #EEF2F8;
  --bleu-hover: #2a4f8f;
  --vert: #198754;
  --vert-clair: #d1e7dd;
  --rouge: #dc3545;
  --orange: #fd7e14;
  --bleu-ciel: #0ea5e9;
  --gris: #6c757d;
  --gris-clair: #f8f9fa;
  --blanc: #ffffff;
  --border: #dee2e6;
  --shadow: 0 2px 8px rgba(0,0,0,0.10);
  --radius: 8px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

/* ── Reset & base ────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: var(--font);
  background: #f0f4f8;
  color: #333;
  min-height: 100vh;
  overflow-x: hidden;
}

/* ── Layout principal ────────────────────────────────────────────────────── */
#app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: linear-gradient(135deg, #16325c 0%, var(--bleu) 55%, #2a4f8f 100%);
  color: white;
  padding: 0 20px;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  box-shadow: 0 2px 6px rgba(0,0,0,0.2);
  position: sticky;
  top: 0;
  z-index: 100;
}
header h1 { font-size: 1.1rem; font-weight: 700; letter-spacing: 0.5px; }
#header-info { font-size: 0.85rem; opacity: 0.85; display: flex; gap: 16px; align-items: center; }
#header-info .badge {
  background: rgba(255,255,255,0.2);
  padding: 2px 10px;
  border-radius: 12px;
  font-size: 0.8rem;
}
#btn-changer-session {
  background: rgba(255,255,255,0.15);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}
#btn-changer-session:hover { background: rgba(255,255,255,0.25); }

main { flex: 1; padding: 20px; max-width: 1400px; margin: 0 auto; width: 100%; box-sizing: border-box; }

/* ── Écrans ──────────────────────────────────────────────────────────────── */
.screen { display: none; }
.screen.active { display: block; }

/* ── Cards ───────────────────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.card-title {
  font-size: 1rem;
  font-weight: 700;
  color: var(--bleu);
  margin-bottom: 14px;
  padding-bottom: 8px;
  border-bottom: 2px solid var(--bleu-clair);
}

/* ── Boutons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 6px;
  border: none;
  cursor: pointer;
  font-size: 0.875rem;
  font-weight: 600;
  line-height: 1.2;
  text-align: center;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
  transition: background 0.15s, transform 0.1s, box-shadow 0.15s;
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 3px 8px rgba(0,0,0,0.15); }
.btn:active { transform: scale(0.97); box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.btn-primary { background: var(--bleu); color: white; }
.btn-primary:hover { background: var(--bleu-hover); }
.btn-success { background: var(--vert); color: white; }
.btn-success:hover { background: #146c43; }
.btn-danger { background: var(--rouge); color: white; }
.btn-outline { background: transparent; border: 1.5px solid var(--bleu); color: var(--bleu); }
.btn-outline:hover { background: var(--bleu-moyen); }
.btn-sm { padding: 4px 10px; font-size: 0.8rem; }

/* Boutons mode Avoir / Échange : état actif bien visible */
/* Au repos : couleur d'identité (avoir rouge, échange bleu ciel) */
#btn-mode-avoir { color: var(--rouge); border-color: var(--rouge); }
#btn-mode-echange { color: var(--bleu-ciel); border-color: var(--bleu-ciel); }
/* Actif : bouton rempli de sa couleur + halo assorti */
.mode-btn.actif { color: white !important; border-color: transparent !important; }
#btn-mode-avoir.actif { background: var(--rouge) !important; box-shadow: 0 0 0 3px rgba(220,53,69,0.35); }
#btn-mode-echange.actif { background: var(--bleu-ciel) !important; box-shadow: 0 0 0 3px rgba(14,165,233,0.40); }
.btn-lg { padding: 10px 24px; font-size: 1rem; }

/* ── Formulaires ─────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 12px; }
.form-group label { display: block; margin-bottom: 4px; font-weight: 600; font-size: 0.85rem; color: #444; }
input[type="text"], input[type="number"], select, textarea {
  width: 100%;
  padding: 8px 12px;
  border: 1.5px solid var(--border);
  border-radius: 6px;
  font-size: 0.9rem;
  font-family: var(--font);
  outline: none;
  transition: border-color 0.15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--bleu); }
input.error { border-color: var(--rouge); }

/* ── Grille commerciaux ──────────────────────────────────────────────────── */
#grille-commerciaux {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 10px;
}
.commercial-card {
  background: white;
  border: 2px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.1s;
  text-align: center;
}
.commercial-card:hover {
  border-color: var(--bleu);
  box-shadow: 0 4px 12px rgba(27,58,107,0.15);
  transform: translateY(-2px);
}
.commercial-card .icon { font-size: 2rem; margin-bottom: 8px; }
.commercial-card .nom { font-weight: 700; font-size: 0.95rem; color: var(--bleu); }
.commercial-card .zone { font-size: 0.8rem; color: var(--gris); margin-top: 4px; }
.commercial-card .nb-clients {
  display: inline-block;
  background: var(--bleu-clair);
  color: var(--bleu);
  border-radius: 10px;
  padding: 2px 8px;
  font-size: 0.75rem;
  margin-top: 6px;
  font-weight: 600;
}

/* ── Sélection client ────────────────────────────────────────────────────── */
#liste-clients { max-height: 420px; overflow-y: auto; border: 1.5px solid var(--border); border-radius: 6px; }
.client-item {
  padding: 10px 14px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  transition: background 0.1s;
}
.client-item:last-child { border-bottom: none; }
.client-item:hover { background: var(--bleu-moyen); }
.client-item .client-nom { font-weight: 600; }
.client-item .client-ville { font-size: 0.82rem; color: var(--gris); }
.client-item .client-code-inline { font-size: 0.78rem; color: #aaa; font-family: monospace; background: #f0f0f0; border-radius: 3px; padding: 0 4px; margin-right: 3px; }

/* ── Catalogue ───────────────────────────────────────────────────────────── */
#layout-commande {
  display: grid;
  grid-template-columns: 1fr 380px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 900px) {
  #layout-commande { grid-template-columns: 1fr; }
  #colonne-panier { order: -1; }
}

#barre-catalogue {
  display: flex;
  gap: 8px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}
#barre-catalogue input { flex: 1; min-width: 0; }
#barre-catalogue select { width: 140px; min-width: 0; }

#grille-articles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 10px;
  max-height: 65vh;
  overflow-y: auto;
  padding-right: 4px;
}
.article-card {
  background: white;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  transition: border-color 0.15s, box-shadow 0.15s;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.article-card { transition: border-color 0.15s, box-shadow 0.15s, transform 0.12s; }
.article-card:hover { border-color: var(--bleu); box-shadow: 0 4px 12px rgba(27,58,107,0.15); transform: translateY(-2px); }
.article-card.en-panier { border-color: var(--vert); background: #f8fff9; }
/* ── Modales : haut atteignable quand le contenu dépasse l'écran ────────────────
   Piège classique (retour Thomas 17/07 sur la fiche client) : `align-items:center`
   + `overflow-y:auto` sur le même conteneur → une modale plus haute que la fenêtre a
   son haut COUPÉ et INATTEIGNABLE, car on ne peut pas scroller au-dessus d'un enfant
   centré en flex. Correctif : `flex-start` sur l'overlay + `margin:auto` sur l'enfant
   → centré quand ça tient, scrollable depuis le haut quand ça dépasse.
   Les overlays portent leur mise en page en style inline → !important nécessaire.
   Concerne aussi la modale de paiement (infos-cde), la création de prospect, etc. */
[id^="overlay-"] { align-items: flex-start !important; }
[id^="overlay-"] > div { margin: auto; }

/* Compte CLIENT : les outils de négociation du VRP n'ont pas lieu d'être — forcer un
   prix (« prix modifié ») et appliquer le « dernier prix payé » sont des prérogatives
   du commercial. Le serveur recalcule de toute façon les prix d'une commande client
   (routes/export.py) : les afficher serait trompeur. Classe posée à la connexion. */
body.profil-client .grp-prix-vrp,
body.profil-client #modale-dernier-prix,
body.profil-client #mg-dernier-prix { display: none !important; }

/* Actions réservées au VRP (ex. « ← Autre client » dans la fiche) : un client n'a
   que sa propre fiche, il n'a nulle part où aller. */
body.profil-client .btn-vrp-only { display: none !important; }

/* Vignette de carte catalogue (brique 2) : 300px / ~10 Ko, chargée en lazy → seules
   les cartes visibles téléchargent. La 1600px n'est servie que dans la fiche article.
   Les articles sans photo gardent un bloc de même hauteur (grille régulière). */
.article-vign {
  aspect-ratio: 1 / 1;
  background: #f6f7f9;
  border-radius: 6px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 8px;
}
.article-vign img { width: 100%; height: 100%; object-fit: contain; }
.article-vign-vide { font-size: 1.6rem; opacity: 0.25; }

.article-ref {
  font-family: monospace;
  /* La réf est l'info que l'on cherche en premier (retour Thomas 16/07) :
     elle prime sur la désignation — tailles inversées + contraste renforcé. */
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--bleu);
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.article-ref .badge-v {
  background: var(--orange);
  color: white;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font);
  font-weight: 700;
}
.article-design {
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.3;
  flex: 1;
}
.article-prix {
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--bleu);
}
.article-famille { font-size: 0.75rem; color: var(--gris); }
.article-region {
  font-size: 0.7rem;
  background: var(--bleu-clair);
  color: var(--bleu);
  padding: 1px 6px;
  border-radius: 10px;
  align-self: flex-start;
}

/* ── Pagination ──────────────────────────────────────────────────────────── */
#pagination {
  display: flex;
  align-items: center;
  gap: 8px;
  justify-content: center;
  margin-top: 10px;
  flex-wrap: wrap;
}
#pagination button {
  padding: 4px 10px;
  border: 1.5px solid var(--border);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
}
#pagination button.actif { background: var(--bleu); color: white; border-color: var(--bleu); }
#pagination button:hover:not(.actif) { background: var(--bleu-moyen); }
#info-pagination { font-size: 0.82rem; color: var(--gris); }

/* ── Panier ──────────────────────────────────────────────────────────────── */
#colonne-panier { position: sticky; top: 72px; }

#panier-header {
  background: var(--bleu);
  color: white;
  padding: 10px 14px;
  border-radius: 8px 8px 0 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 700;
}
#panier-body {
  border: 1.5px solid var(--bleu);
  border-top: none;
  border-radius: 0 0 8px 8px;
  max-height: 55vh;
  overflow-y: auto;
  background: white;
}
#panier-vide {
  padding: 30px;
  text-align: center;
  color: var(--gris);
  font-size: 0.9rem;
}
.panier-ligne {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px;
  font-size: 0.85rem;
}
.panier-ligne:last-child { border-bottom: none; }
.panier-ligne-ref { font-family: monospace; font-size: 0.8rem; color: var(--gris); }
.panier-ligne-design { font-weight: 600; grid-column: 1; font-size: 0.82rem; line-height: 1.3; }
.panier-ligne-motif { font-size: 0.78rem; color: var(--orange); font-style: italic; }
.panier-ligne-actions {
  grid-column: 2;
  grid-row: 1 / 4;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
}
.panier-ligne-total { font-weight: 700; color: var(--bleu); font-size: 0.9rem; }
.panier-ligne-detail { font-size: 0.75rem; color: var(--gris); }
.btn-delete-ligne {
  background: none;
  border: none;
  color: var(--rouge);
  cursor: pointer;
  font-size: 1rem;
  padding: 2px;
  line-height: 1;
}
.btn-delete-ligne:hover { color: #900; }

#panier-totaux {
  background: var(--bleu-moyen);
  border: 1.5px solid var(--bleu);
  border-top: none;
  border-radius: 0 0 8px 8px;
  padding: 10px 14px;
}
.totaux-ligne {
  display: flex;
  justify-content: space-between;
  font-size: 0.85rem;
  padding: 2px 0;
}
.totaux-ligne.ttc {
  font-weight: 700;
  font-size: 1rem;
  color: var(--bleu);
  margin-top: 6px;
  padding-top: 6px;
  border-top: 2px solid var(--bleu);
}

/* Action principale : Finaliser la commande — bouton mis en avant */
.btn-finaliser {
  display: flex;
  width: 100%;
  justify-content: center;
  margin-top: 12px;
  padding: 15px 18px;
  font-size: 1.12rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: white;
  background: linear-gradient(135deg, #1aa15f 0%, var(--vert) 100%);
  border: none;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(25,135,84,0.35);
}
.btn-finaliser:hover { background: linear-gradient(135deg, #17924f 0%, #157347 100%); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(25,135,84,0.45); }
.btn-finaliser:active { transform: scale(0.99); }

/* Documents : zone secondaire, discrète */
#boutons-export { margin-top: 12px; background: var(--gris-clair); padding: 8px 10px 10px; border-radius: 8px; border: 1px solid var(--border); }
.boutons-export-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.4px; color: var(--gris); margin-bottom: 6px; font-weight: 600; }
.boutons-export-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#boutons-export .btn { justify-content: center; font-size: 0.74rem; padding: 6px 8px; box-shadow: none; }

#boutons-bc { margin-top: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
#boutons-bc .btn { justify-content: center; font-size: 0.76rem; padding: 6px 6px; }

/* ── BCs historiques ─────────────────────────────────────────────────────── */
#bcs-liste { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.bc-hist-item {
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  font-size: 0.82rem;
}
.bc-hist-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 12px;
  background: var(--bleu-moyen);
  cursor: pointer;
  user-select: none;
  gap: 8px;
}
.bc-hist-header:hover { background: var(--bleu-clair); }
.bc-hist-client { font-weight: 700; font-size: 0.84rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bc-hist-stats { font-size: 0.76rem; color: var(--gris); margin-top: 1px; }
.bc-hist-body { padding: 8px 12px; border-top: 1px solid var(--border); background: #fff; }
.bc-hist-ligne {
  display: grid;
  grid-template-columns: 50px 1fr 30px 60px;
  gap: 6px;
  align-items: center;
  padding: 3px 0;
  border-bottom: 1px solid #f0f0f0;
  font-size: 0.77rem;
}
.bc-hist-ligne:last-child { border-bottom: none; }
.bc-hist-ref { font-family: monospace; color: var(--gris); font-size: 0.72rem; }
.bc-hist-design { color: #333; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.bc-hist-qte { color: var(--gris); text-align: center; }
.bc-hist-total { text-align: right; font-weight: 600; color: var(--bleu); }
.bc-hist-exports { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 8px; padding-top: 8px; border-top: 1px solid var(--border); }
.btn-xs { padding: 3px 7px !important; font-size: 0.7rem !important; }

/* ── Modale ajout article ────────────────────────────────────────────────── */
#overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 220;   /* au-dessus du bandeau « Mode admin » (fixed bottom, z-index 200)
                     qui sinon recouvrait le bouton « Ajouter au panier » */
  justify-content: center;
  align-items: center;
  padding: 20px;
}
#overlay.open { display: flex; }
#modale {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  position: relative;
}
#modale-titre {
  font-size: 1rem;
  font-weight: 700;
  color: var(--bleu);
  margin-bottom: 4px;
}
#modale-ref {
  font-family: monospace;
  font-size: 0.8rem;
  color: var(--gris);
  margin-bottom: 14px;
}
#modale-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--gris);
  line-height: 1;
}
#modale-close:hover { color: var(--rouge); }

/* ── Badge gamme (catalogue) ─────────────────────────────────────────────── */
.badge-gamme {
  background: #e8f4fd;
  color: #0c63e4;
  font-size: 0.65rem;
  padding: 1px 5px;
  border-radius: 4px;
  font-family: var(--font);
  font-weight: 700;
  letter-spacing: 0.02em;
}
.article-card.est-gamme { border-left: 3px solid #0c63e4; }

/* ── Modale gamme ────────────────────────────────────────────────────────── */
#overlay-gamme {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 210;
  justify-content: center;
  align-items: center;
  padding: 20px;
}
#overlay-gamme.open { display: flex; }
#modale-gamme {
  background: white;
  border-radius: var(--radius);
  padding: 24px;
  width: 100%;
  max-width: 520px;
  max-height: 85vh;
  overflow-y: auto;
  box-shadow: 0 8px 32px rgba(0,0,0,0.2);
  position: relative;
}
#modale-gamme-close {
  position: absolute;
  top: 12px;
  right: 14px;
  background: none;
  border: none;
  font-size: 1.4rem;
  cursor: pointer;
  color: var(--gris);
  line-height: 1;
}
#modale-gamme-close:hover { color: var(--rouge); }
.mg-header {
  display: grid;
  grid-template-columns: 1fr 90px 80px;
  gap: 8px;
  padding: 6px 10px;
  background: var(--bleu);
  color: white;
  font-size: 0.78rem;
  font-weight: 700;
  border-radius: 4px 4px 0 0;
}
.mg-ligne {
  display: grid;
  grid-template-columns: 1fr 90px 80px;
  gap: 8px;
  align-items: center;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  transition: background 0.1s;
}
.mg-ligne:last-child { border-bottom: none; }
.mg-ligne:hover { background: var(--bleu-moyen); }
.mg-ligne.active { background: #f0fff4; }
.mg-label { font-size: 0.88rem; font-weight: 500; }
.mg-px-net { font-size: 0.85rem; color: var(--bleu); font-weight: 600; text-align: right; }
.mg-qte {
  width: 70px;
  padding: 4px 6px;
  border: 1.5px solid var(--border);
  border-radius: 4px;
  font-size: 0.9rem;
  text-align: center;
}
.mg-qte:focus { border-color: var(--bleu); outline: none; }
.mg-qte.non-zero { border-color: var(--vert); background: #f0fff4; font-weight: 700; }
#mg-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-top: 14px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
  gap: 12px;
}

/* ── Info-bulle erreur ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--rouge);
  color: white;
  padding: 12px 18px;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow);
  z-index: 500;
  opacity: 0;
  transform: translateY(10px);
  transition: opacity 0.2s, transform 0.2s;
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--vert); }
.toast.warn { background: var(--orange); }

/* ── Panneau N-1 (fiche client) ─────────────────────────────────────────── */
.n1-panel {
  margin-top: 14px;
  background: #f0f4ff;
  border: 1px solid #c5d3f5;
  border-radius: 8px;
  padding: 12px 14px;
}
.n1-panel-titre {
  font-size: 0.82rem;
  font-weight: 700;
  color: var(--bleu);
  margin-bottom: 8px;
}
.n1-liste { display: flex; flex-direction: column; gap: 0; }
.n1-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  padding: 5px 0;
  border-bottom: 1px solid #dde6ff;
}
.n1-item:last-child { border-bottom: none; }
.n1-ref { font-weight: 700; color: var(--bleu); min-width: 58px; flex-shrink: 0; }
.n1-design { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--texte); }
.n1-qte { font-weight: 700; color: var(--orange); min-width: 38px; text-align: right; flex-shrink: 0; }
.n1-ajouter {
  font-size: 0.78rem;
  padding: 2px 8px;
  border: 1px solid var(--bleu);
  color: var(--bleu);
  background: white;
  border-radius: 4px;
  cursor: pointer;
  flex-shrink: 0;
  font-weight: 700;
  line-height: 1.4;
}
.n1-ajouter:hover { background: var(--bleu); color: white; }
.n1-suite { font-size: 0.75rem; color: var(--gris); margin-top: 6px; font-style: italic; }

/* ── Oublis N-1 (modale avant finalisation) ─────────────────────────────── */
.n1-oubli-item {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.82rem;
  padding: 6px 0;
  border-bottom: 1px solid var(--border);
}
.n1-oubli-item:last-child { border-bottom: none; }
.n1-oubli-item .n1-ref { min-width: 58px; }
.n1-oubli-item .n1-qte { min-width: 80px; }
.n1-oubli-clic { cursor: pointer; border-radius: 6px; padding-left: 6px; padding-right: 6px; transition: background 0.12s; }
.n1-oubli-clic:hover { background: var(--bleu-moyen); }
.n1-oubli-clic:active { background: #dbe7f5; }
.n1-oubli-plus {
  min-width: 26px; height: 26px; flex-shrink: 0;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bleu); color: #fff; border-radius: 6px;
  font-weight: 700; font-size: 0.95rem;
}

/* ── Alerte quantité < N-1 (modale persistante) ─────────────────────────── */
.n1-alerte-ref { font-weight: 700; color: var(--bleu); margin-bottom: 10px; }
.n1-alerte-lignes {
  font-size: 0.9rem;
  background: var(--bleu-moyen);
  border-radius: 8px;
  padding: 8px 14px;
}
.n1-alerte-lignes > div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 0;
}
.n1-alerte-lignes .n1-alerte-tot {
  border-top: 1px solid var(--border);
  margin-top: 2px;
  font-weight: 700;
}
.n1-alerte-manque {
  margin-top: 10px;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--orange);
  text-align: center;
}
.n1-alerte-reste { font-size: 0.75rem; color: var(--gris); margin-top: 10px; font-style: italic; }

/* Oublis : chiffres an dernier / pris / manque */
.n1-oubli-chiffres { font-size: 0.76rem; color: var(--gris); white-space: nowrap; flex-shrink: 0; }
.n1-oubli-chiffres .n1-manque { color: var(--orange); }

/* Panneau fiche : cumul saison en cours (vert = rattrapé, orange = en retard) */
.n1-ok { color: var(--vert); }
.n1-retard { color: var(--orange); }

/* ── Spinner ─────────────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 18px; height: 18px;
  border: 2.5px solid rgba(255,255,255,0.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}
.spinner.dark {
  border-color: rgba(27,58,107,0.2);
  border-top-color: var(--bleu);
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Badges ──────────────────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-bleu { background: var(--bleu-clair); color: var(--bleu); }
.badge-vert { background: var(--vert-clair); color: var(--vert); }
.badge-orange { background: #fff3cd; color: #664d03; }

/* Pastille client de l'en-tête : elle OUVRE la fiche (voir/modifier à tout moment, même
   pendant la commande). Rendue visiblement cliquable — sinon personne ne le devine. */
.badge-fiche { border: 1px solid rgba(255,255,255,0.55); }
.badge-fiche::after { content: " 🪪"; }
.badge-fiche:hover { background: rgba(255,255,255,0.18); text-decoration: underline; }

/* ── Boutons header (déconnexion, règlements) ────────────────────────────── */
/* Surcharge .btn-outline (texte bleu foncé, invisible sur l'en-tête sombre) → texte clair. */
#btn-deconnexion,
#btn-encaissements {
  background: rgba(255,255,255,0.10);
  border: 1px solid rgba(255,255,255,0.25);
  color: white;
  padding: 4px 12px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.8rem;
}
#btn-deconnexion:hover,
#btn-encaissements:hover { background: rgba(255,255,255,0.22); }

/* ── Écran Login ─────────────────────────────────────────────────────────── */
#ecran-login.active {
  display: flex;
  justify-content: center;
  align-items: center;
  min-height: calc(100vh - 52px);
}

.login-wrap {
  width: 100%;
  max-width: 380px;
  padding: 20px;
}

.login-logo {
  text-align: center;
  margin-bottom: 28px;
}
.login-logo img {
  width: auto;
  max-width: 260px;
  max-height: 70px;
  height: auto;
  object-fit: contain;
  margin: 0 auto 10px;
  display: block;
}
.login-title {
  font-size: 1.4rem;
  font-weight: 800;
  color: var(--bleu);
  letter-spacing: 2px;
}
.login-subtitle {
  font-size: 0.85rem;
  color: var(--gris);
  margin-top: 4px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.login-card {
  padding: 28px 24px;
}

.login-erreur {
  background: #f8d7da;
  color: var(--rouge);
  border-radius: 6px;
  padding: 10px 14px;
  font-size: 0.88rem;
  margin-bottom: 8px;
}

/* ── Suggestions motif/complément ───────────────────────────────────────── */
.suggestions { display: flex; flex-wrap: wrap; gap: 4px; margin: 4px 0 8px; min-height: 10px; }
.suggestion-badge { background: var(--bleu-moyen); border: 1px solid var(--border); border-radius: 12px; padding: 2px 8px; font-size: 0.75rem; cursor: pointer; }
.suggestion-badge:hover { background: var(--bleu-clair, #D4E1F7); }

/* ── Bouton corriger ligne panier ────────────────────────────────────────── */
.btn-edit-ligne {
  background: none;
  border: none;
  color: var(--bleu);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 2px;
  line-height: 1;
}
.btn-edit-ligne:hover { color: var(--bleu-hover); }

/* ── QTE inline dans panier ──────────────────────────────────────────────── */
.qte-input {
  width: 52px;
  padding: 3px 6px;
  text-align: center;
  font-size: 0.85rem;
  border: 1.5px solid var(--border);
  border-radius: 4px;
}
.remise-input {
  width: 56px;
  padding: 3px 6px;
  font-size: 0.82rem;
  border: 1.5px solid var(--border);
  border-radius: 4px;
}

/* ════════════════════════════════════════════════════════════════════════════
   RESPONSIVE — Tablette (max 900px) et Mobile (max 600px)
   Approche : tout ce qui peut déborder est contraint à 100% de la largeur
   ════════════════════════════════════════════════════════════════════════════ */

/* Base anti-débordement universelle */
*, *::before, *::after { box-sizing: border-box; min-width: 0; }
html { overflow-x: hidden; }
body { overflow-x: hidden; max-width: 100%; }
img, video, iframe { max-width: 100%; height: auto; }

/* ── Tablette (601px → 900px) ─────────────────────────────────────────────── */
@media (max-width: 900px) {
  main { padding: 12px; }
  #grille-articles { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
}

/* ── Mobile (≤ 600px) ────────────────────────────────────────────────────── */
@media (max-width: 600px) {

  /* GLOBAL */
  main { padding: 8px; }
  .card { padding: 12px; }

  /* HEADER */
  header {
    padding: 6px 8px;
    height: auto;
    min-height: 44px;
    flex-wrap: wrap;
    gap: 4px;
  }
  header h1 {
    font-size: 0.8rem;
    letter-spacing: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 150px;
  }
  #header-info { font-size: 0.72rem; gap: 4px; flex-wrap: wrap; }
  #header-info .badge {
    padding: 2px 6px;
    font-size: 0.68rem;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }
  #btn-changer-session, #btn-deconnexion, #btn-encaissements { font-size: 0.68rem; padding: 2px 6px; }

  /* CATALOGUE */
  #barre-catalogue { flex-direction: column; gap: 6px; }
  #barre-catalogue input, #barre-catalogue select { width: 100%; min-width: 0; }
  #grille-articles {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 6px;
    max-height: none;
  }
  .article-card { padding: 8px; }
  .article-design { font-size: 0.8rem; }
  #pagination { flex-wrap: wrap; gap: 4px; justify-content: center; }

  /* PANIER */
  #colonne-panier { font-size: 0.82rem; }
  #panier-header { padding: 8px 10px; }
  .boutons-export-grid { grid-template-columns: 1fr 1fr; }
  #boutons-bc { grid-template-columns: 1fr 1fr; }
  #boutons-bc .btn { font-size: 0.72rem; padding: 5px; }
  .btn-finaliser { font-size: 1.05rem; padding: 14px 16px; }

  /* MODALES — collées en bas, pleine largeur */
  #overlay,
  #overlay-gamme,
  [id^="overlay-"] {
    align-items: flex-end !important;
    padding: 0 !important;
  }
  #modale,
  #modale-gamme {
    max-width: 100% !important;
    width: 100% !important;
    border-radius: var(--radius) var(--radius) 0 0 !important;
    max-height: 92vh;
    overflow-y: auto;
    padding: 16px 12px !important;
    margin: 0 !important;
  }
  [id^="overlay-"] > div {
    max-width: 100% !important;
    width: 100% !important;
    border-radius: var(--radius) var(--radius) 0 0 !important;
    margin: 0 !important;
    padding: 16px 12px !important;
    max-height: 92vh;
    overflow-y: auto;
  }

  /* GRILLES EN 1 COLONNE dans toutes les modales */
  #fiche-lecture > div,
  #fiche-edition > div,
  [id^="overlay-"] > div > div[style*="grid"],
  [id^="overlay-"] div[style*="grid-template-columns:1fr 1fr"] {
    grid-template-columns: 1fr !important;
  }

  /* LISTE CLIENTS */
  #liste-clients { max-height: 55vh; }
  .client-item { padding: 8px 10px; }

  /* GRILLE COMMERCIAUX */
  #grille-commerciaux { grid-template-columns: repeat(2, 1fr); gap: 8px; }

  /* BC HISTORIQUE */
  .bc-hist-ligne { grid-template-columns: 50px 1fr 30px 55px; font-size: 0.78rem; }
  .bc-hist-exports { gap: 3px; }
  .bc-hist-exports .btn { font-size: 0.68rem; padding: 3px 5px; }

  /* LOGIN */
  .login-wrap { padding: 20px 12px; }
  .login-card { padding: 20px 14px; }
  .login-logo img { max-width: 200px; max-height: 56px; }

  /* MODALE GAMME - grille tailles */
  .mg-header,
  #mg-grille .mg-ligne {
    grid-template-columns: 1fr 70px 80px;
    font-size: 0.82rem;
  }

  /* BOUTONS généraux */
  .btn { font-size: 0.8rem; padding: 7px 10px; }
  .btn-sm { font-size: 0.72rem; padding: 4px 8px; }

  /* DASHBOARD mobile */
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .dashboard-wrap { padding: 10px 8px 70px; }
  .dashboard-hist-table th,
  .dashboard-hist-table td { font-size: 0.72rem; padding: 5px 6px; }
}

/* ── Nav bas ───────────────────────────────────────────────────────────────── */
#nav-bas {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bleu);
  z-index: 150;
  display: flex;
  justify-content: space-around;
  padding: 6px 0 8px;
  box-shadow: 0 -2px 8px rgba(0,0,0,0.2);
}
#nav-bas button {
  background: transparent;
  border: none;
  color: rgba(255,255,255,0.85);
  font-size: 0.72rem;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 4px 16px;
  border-radius: 6px;
  transition: background 0.15s, color 0.15s;
  min-width: 64px;
}
#nav-bas button:hover,
#nav-bas button.active {
  background: rgba(255,255,255,0.15);
  color: white;
}
#nav-bas .nav-icon { font-size: 1.2rem; }

/* Padding body quand nav visible */
body.nav-visible main { padding-bottom: 62px; }

/* ── Dashboard ─────────────────────────────────────────────────────────────── */
.dashboard-wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 16px 12px 70px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* Bouton "Nouvelle commande" — appel à l'action principal du dashboard (orange) */
.btn-nouvelle-cmd {
  display: flex;
  width: 100%;
  justify-content: center;
  padding: 16px 18px;
  font-size: 1.15rem;
  font-weight: 800;
  letter-spacing: 0.3px;
  color: white;
  background: linear-gradient(135deg, #ff9a3d 0%, var(--orange) 100%);
  border: none;
  border-radius: 10px;
  box-shadow: 0 4px 14px rgba(253,126,20,0.38);
}
.btn-nouvelle-cmd:hover { background: linear-gradient(135deg, #f78a22 0%, #e96f0a 100%); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(253,126,20,0.48); }
.btn-nouvelle-cmd:active { transform: scale(0.99); }

/* Variante orange (ex. petit bouton "Nouvelle commande" de l'historique) */
.btn-orange { background: var(--orange); color: white; }
.btn-orange:hover { background: #e96f0a; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.kpi-card {
  background: white;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
  text-align: center;
}
.kpi-label {
  font-size: 0.78rem;
  color: var(--gris);
  margin-bottom: 6px;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}
.kpi-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--bleu);
  line-height: 1.2;
  word-break: break-word;
}

/* L'historique peut être plus large que l'écran : scroll horizontal interne
   au lieu de déborder hors de la carte. */
#dashboard-liste,
#historique-modale-liste { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.dashboard-chart-card canvas {
  max-height: 160px;
}

.dashboard-hist-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.82rem;
}
.dashboard-hist-table th {
  background: var(--bleu-moyen);
  color: var(--bleu);
  font-weight: 600;
  padding: 8px 10px;
  text-align: left;
  border-bottom: 2px solid var(--border);
  white-space: nowrap;
}
.dashboard-hist-table td {
  padding: 7px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.dashboard-hist-table tr:last-child td { border-bottom: none; }
.dashboard-hist-table tr:hover td { background: var(--bleu-moyen); cursor: pointer; }
.badge-etat {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 10px;
  font-size: 0.72rem;
  font-weight: 700;
  white-space: nowrap;
}
.badge-etat.transmis { background: var(--vert-clair); color: var(--vert); }
.badge-etat.en-cours { background: #fff3cd; color: #9a6700; }
.badge-etat.draft { background: #fff3cd; color: #856404; }

/* ── Cartes commande (dashboard + historique) ──────────────────────────────── */
.cmd-cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
  gap: 12px;
}
.cmd-card {
  background: white;
  border: 1px solid var(--border);
  border-left: 4px solid var(--vert);
  border-radius: 10px;
  padding: 12px 14px;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.12s, border-color 0.15s;
  display: flex;
  flex-direction: column;
  gap: 7px;
}
.cmd-card:hover { box-shadow: 0 4px 14px rgba(27,58,107,0.16); transform: translateY(-2px); }
.cmd-card.encours { border-left-color: var(--orange); background: #fffdf7; }
.cmd-card-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cmd-card-ref { font-family: monospace; font-size: 0.9rem; color: var(--bleu); }
.cmd-card-client { font-weight: 700; font-size: 0.95rem; color: #222; line-height: 1.25; }
.cmd-card-meta { display: flex; justify-content: space-between; gap: 8px; font-size: 0.8rem; color: var(--gris); }
.cmd-card-foot {
  display: flex; justify-content: space-between; align-items: baseline;
  border-top: 1px dashed var(--border); padding-top: 7px; margin-top: 1px;
}
.cmd-card-nb { font-size: 0.8rem; color: var(--gris); }
.cmd-card-total { font-size: 1.05rem; font-weight: 800; color: var(--bleu); }
