:root {
  --fond: #F4F5F8; --carte: #FFFFFF; --texte: #161B26; --doux: #5D6475; --ligne: #E3E6EC;
  --marine: #14213D; --or: #F2B416; --or-fonce: #A87A00; --vert: #1E8E4E; --rouge: #C8372D; --bleu: #1F5FBF;
  --rayon: 12px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { background: var(--fond); color: var(--texte); font-family: 'Inter', system-ui, sans-serif; font-size: 15px; line-height: 1.45; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--bleu); }
.cachee { display: none !important; }
.chargement { padding: 40px; text-align: center; color: var(--doux); }

/* Barre du haut */
.barre { position: sticky; top: 0; z-index: 10; background: var(--marine); color: #fff; display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.barre .marque { font-weight: 800; letter-spacing: .3px; white-space: nowrap; }
.barre .marque span { color: var(--or); }
.barre nav { display: flex; gap: 4px; margin-left: 8px; overflow-x: auto; }
.barre nav a { color: #C9D2E6; text-decoration: none; padding: 7px 11px; border-radius: 8px; font-weight: 600; font-size: 14px; white-space: nowrap; }
.barre nav a.actif, .barre nav a:hover { background: rgba(255,255,255,.12); color: #fff; }
.barre .qui { margin-left: auto; font-size: 13px; color: #C9D2E6; white-space: nowrap; }
@media (max-width: 760px) { .barre { flex-wrap: wrap; } .barre nav { order: 3; width: 100%; margin-left: 0; } .barre .qui { margin-left: auto; } }

main { max-width: 1100px; margin: 0 auto; padding: 18px 16px 60px; }
h1 { font-size: 22px; font-weight: 800; margin-bottom: 4px; }
h2 { font-size: 17px; font-weight: 700; margin: 18px 0 10px; }
.sous { color: var(--doux); margin-bottom: 16px; }
.entete { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }

.carte { background: var(--carte); border: 1px solid var(--ligne); border-radius: var(--rayon); padding: 16px; }
.carte + .carte { margin-top: 12px; }

/* Boutons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--ligne); background: #fff; padding: 9px 14px; border-radius: 9px; font-weight: 600; cursor: pointer; text-decoration: none; color: var(--texte); white-space: nowrap; }
.btn:hover { border-color: #C5CAD4; }
.btn.principal { background: var(--marine); border-color: var(--marine); color: #fff; }
.btn.or { background: var(--or); border-color: var(--or); color: #1A1406; }
.btn.vert { background: var(--vert); border-color: var(--vert); color: #fff; }
.btn.rouge { color: var(--rouge); }
.btn.petit { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: default; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }

/* Formulaires */
label { display: block; font-size: 13px; font-weight: 600; color: var(--doux); margin-bottom: 4px; }
input, select, textarea { width: 100%; border: 1px solid #CDD2DC; border-radius: 9px; padding: 9px 11px; background: #fff; }
input:focus, select:focus, textarea:focus { outline: 2px solid #9DB8E8; border-color: var(--bleu); }
textarea { min-height: 70px; resize: vertical; }
.grille { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.champ { margin-bottom: 12px; }
.erreur { background: #FDECEA; color: var(--rouge); border: 1px solid #F5C2BD; padding: 9px 12px; border-radius: 9px; margin-bottom: 12px; }
.info { background: #EEF4FD; color: #1B4C93; border: 1px solid #C8DBF5; padding: 9px 12px; border-radius: 9px; margin-bottom: 12px; font-size: 14px; }

/* Connexion */
.connexion { max-width: 380px; margin: 8vh auto; padding: 0 16px; }
.connexion .logos { display: flex; justify-content: center; align-items: center; gap: 18px; margin-bottom: 18px; }
.connexion .logos img { height: 54px; }

/* Choix société */
.societes { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.societe { border: 2px solid var(--ligne); border-radius: var(--rayon); padding: 10px; background: #fff; cursor: pointer; display: flex; align-items: center; justify-content: center; min-height: 64px; }
.societe img { max-height: 44px; max-width: 100%; }
.societe.choisie { border-color: var(--or); box-shadow: 0 0 0 3px rgba(242,180,22,.25); }

/* Listes */
.filtres { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filtres input { max-width: 260px; }
.filtres select { width: auto; }
.onglets { display: flex; gap: 6px; margin-bottom: 12px; }
.onglets a { padding: 7px 14px; border-radius: 99px; text-decoration: none; color: var(--doux); font-weight: 600; background: #fff; border: 1px solid var(--ligne); }
.onglets a.actif { background: var(--marine); color: #fff; border-color: var(--marine); }
table.liste { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--ligne); border-radius: var(--rayon); overflow: hidden; }
table.liste th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--doux); background: #F8F9FB; padding: 9px 10px; border-bottom: 1px solid var(--ligne); }
table.liste td { padding: 10px; border-bottom: 1px solid var(--ligne); vertical-align: top; }
table.liste tr.cliquable { cursor: pointer; }
table.liste tr.cliquable:hover td { background: #FAFBFD; }
.droite { text-align: right; }
.num { font-variant-numeric: tabular-nums; white-space: nowrap; }
.vide { padding: 28px; text-align: center; color: var(--doux); background: #fff; border: 1px dashed #CDD2DC; border-radius: var(--rayon); }
@media (max-width: 760px) {
  table.liste thead { display: none; }
  table.liste, table.liste tbody, table.liste tr, table.liste td { display: block; width: 100%; }
  table.liste tr { border-bottom: 1px solid var(--ligne); padding: 8px 4px; }
  table.liste td { border: none; padding: 2px 8px; }
  table.liste td[data-l]::before { content: attr(data-l) ' : '; color: var(--doux); font-size: 12px; }
}

/* Statuts */
.statut { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; white-space: nowrap; }
.s-brouillon { background: #ECEEF2; color: #4A5163; }
.s-envoye { background: #E5EEFC; color: #1F5FBF; }
.s-accepte, .s-fne { background: #E3F4EA; color: #1E7A45; }
.s-refuse, .s-annule { background: #FBE7E5; color: #A8322A; }
.s-a_facturer { background: #FFF4D6; color: #8A6200; }
.s-payee { background: #1E8E4E; color: #fff; }
.code { display: inline-block; font-size: 11px; font-weight: 800; padding: 1px 6px; border-radius: 5px; letter-spacing: .4px; }
.c-VSF { background: #E2EAF7; color: #0E3F8F; }
.c-AUR { background: #FFF1C7; color: #6B4E00; }

/* Lignes du document */
.lignes { width: 100%; border-collapse: collapse; }
.lignes th { text-align: left; font-size: 12px; color: var(--doux); padding: 6px 4px; }
.lignes td { padding: 4px; vertical-align: top; }
.lignes input { padding: 7px 8px; }
.lignes .q { width: 80px; } .lignes .u { width: 80px; } .lignes .p { width: 130px; } .lignes .t { width: 120px; text-align: right; padding-top: 12px; }
@media (max-width: 760px) {
  .lignes thead { display: none; }
  .lignes tr { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; padding: 10px 0; border-bottom: 1px dashed var(--ligne); }
  .lignes td { padding: 0; }
  .lignes td.d { grid-column: 1 / -1; }
  .lignes .q, .lignes .u, .lignes .p, .lignes .t { width: auto; }
  .lignes td.t { grid-column: 1 / 3; text-align: left; padding-top: 4px; }
  .lignes td.q::before, .lignes td.u::before, .lignes td.p::before { display: block; font-size: 11px; color: var(--doux); font-weight: 600; margin-bottom: 2px; }
  .lignes td.q::before { content: 'Quantité'; } .lignes td.u::before { content: 'Unité'; } .lignes td.p::before { content: 'Prix unit. HT'; }
}
.totaux { margin-left: auto; max-width: 340px; }
.totaux div { display: flex; justify-content: space-between; padding: 5px 0; }
.totaux .ttc { font-weight: 800; font-size: 18px; border-top: 2px solid var(--texte); margin-top: 4px; padding-top: 8px; }

.deux { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
@media (max-width: 860px) { .deux { grid-template-columns: 1fr; } }
.histo { font-size: 13px; color: var(--doux); }
.histo li { list-style: none; padding: 5px 0; border-bottom: 1px solid var(--ligne); }

/* Fenêtre */
.fenetre { position: fixed; inset: 0; z-index: 50; background: rgba(10,15,30,.5); display: flex; align-items: center; justify-content: center; padding: 16px; }
.fenetre-boite { background: #fff; border-radius: 14px; padding: 18px; width: 100%; max-width: 520px; max-height: 90vh; overflow: auto; }
.toast { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); background: var(--marine); color: #fff; padding: 10px 18px; border-radius: 10px; z-index: 60; font-weight: 600; }

/* Document imprimable (A4) */
.papier-zone { background: #DADDE3; padding: 16px; border-radius: var(--rayon); overflow: hidden; }
@media (max-width: 760px) { .papier-zone { padding: 8px; } }
.papier { width: 210mm; min-height: 297mm; margin: 0 auto; background: #fff; padding: 14mm 14mm 12mm; color: #1A1D24; font-size: 10pt; position: relative; }
.papier .p-haut { display: flex; justify-content: space-between; align-items: flex-start; gap: 10mm; padding-bottom: 5mm; border-bottom: 2px solid var(--accent); }
.papier .p-logo { height: 22mm; }
.papier .p-soc { text-align: right; font-size: 8.5pt; color: #444; line-height: 1.45; }
.papier .p-soc b { font-size: 11pt; color: #111; }
.papier .p-titre { display: flex; justify-content: space-between; align-items: flex-end; margin: 7mm 0 5mm; }
.papier .p-titre h1 { font-size: 20pt; letter-spacing: 1px; color: var(--accent2, #111); }
.papier .p-ref { text-align: right; font-size: 9.5pt; }
.papier .p-blocs { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm; margin-bottom: 6mm; }
.papier .p-bloc { border: 1px solid #DDD; border-radius: 3mm; padding: 3.5mm 4mm; font-size: 9.5pt; }
.papier .p-bloc .l { font-size: 7.5pt; text-transform: uppercase; letter-spacing: .8px; color: #777; font-weight: 700; margin-bottom: 1.5mm; }
.papier table { width: 100%; border-collapse: collapse; font-size: 9.5pt; }
.papier th { background: var(--accent); color: #fff; text-align: left; padding: 2.5mm 3mm; font-size: 8.5pt; }
.papier td { padding: 2.5mm 3mm; border-bottom: 1px solid #E5E5E5; vertical-align: top; }
.papier .p-tot { display: flex; justify-content: flex-end; margin-top: 4mm; }
.papier .p-tot table { width: 75mm; }
.papier .p-tot td { border: none; padding: 1.4mm 3mm; }
.papier .p-tot tr.ttc td { background: var(--accent); color: #fff; font-weight: 800; font-size: 11pt; }
.papier .p-lettres { margin-top: 4mm; font-size: 9pt; font-style: italic; }
.papier .p-cond { margin-top: 5mm; font-size: 8.5pt; color: #333; white-space: pre-line; }
.papier .p-sign { display: grid; grid-template-columns: 1fr 1fr; gap: 10mm; margin-top: 10mm; font-size: 9pt; }
.papier .p-sign div { border-top: 1px solid #999; padding-top: 2mm; height: 24mm; }
.papier .p-note { margin-top: 6mm; padding: 3mm 4mm; background: #FFF8E1; border: 1px solid #F0D58A; border-radius: 2mm; font-size: 8.5pt; }
.papier .p-pied { position: absolute; left: 14mm; right: 14mm; bottom: 8mm; font-size: 7.5pt; color: #777; text-align: center; border-top: 1px solid #DDD; padding-top: 2mm; }

@media print {
  body * { visibility: hidden; }
  .papier, .papier * { visibility: visible; }
  .papier { position: absolute; left: 0; top: 0; margin: 0; zoom: 1 !important; }
  @page { size: A4; margin: 0; }
}
