/* ALIZE SOLUTION — feuille de style */
/* Couleurs : clair par défaut, sombre au choix ou selon l'appareil */
:root {
  --fond: #F3F1EE; --surface: #FBFAF8; --menu: #ECE8E3; --survol: #F1ECE6; --entete-tableau: #F7F4F0;
  --encre: #2F2A26; --encre-douce: #6F665E; --trait: #E3DDD6; --trait-fort: #CDC4BA;
  --accent: #7A6550; --accent-fonce: #5F4E3E; --accent-pale: #EFE8DF; --sur-accent: #FFFDF9;
  --cafe: #6B4A2E; --cafe-pale: #F2EAE0;
  --rouge: #A3443A; --rouge-pale: #F8E9E6; --vert: #4F7A4C; --vert-pale: #E8F0E5; --ambre: #8A6420; --ambre-pale: #F7EDDA;
  --voile: rgba(47, 42, 38, .4); --ombre: 0 1px 2px rgba(47, 42, 38, .05), 0 6px 20px rgba(47, 42, 38, .06);
  --police: 'Atkinson Hyperlegible Next', 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --titre: 'Cormorant Garamond', 'Cormorant', Garamond, Georgia, serif;
  --r: 8px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="clair"]) {
    --fond: #1B1917; --surface: #23201D; --menu: #1F1C1A; --survol: #2A2622; --entete-tableau: #26231F;
    --encre: #E9E3DB; --encre-douce: #A89D91; --trait: #36312C; --trait-fort: #4B443D;
    --accent: #C9AE8E; --accent-fonce: #DCC4A6; --accent-pale: #332B23; --sur-accent: #1B1917;
    --cafe: #D9B48C; --cafe-pale: #3A2E22;
    --rouge: #E58A7E; --rouge-pale: #3D2421; --vert: #9CC59A; --vert-pale: #243324; --ambre: #E2B866; --ambre-pale: #3A2F1A;
    --voile: rgba(0, 0, 0, .55); --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}
:root[data-theme="sombre"] {
  --fond: #1B1917; --surface: #23201D; --menu: #1F1C1A; --survol: #2A2622; --entete-tableau: #26231F;
  --encre: #E9E3DB; --encre-douce: #A89D91; --trait: #36312C; --trait-fort: #4B443D;
  --accent: #C9AE8E; --accent-fonce: #DCC4A6; --accent-pale: #332B23; --sur-accent: #1B1917;
  --cafe: #D9B48C; --cafe-pale: #3A2E22;
  --rouge: #E58A7E; --rouge-pale: #3D2421; --vert: #9CC59A; --vert-pale: #243324; --ambre: #E2B866; --ambre-pale: #3A2F1A;
  --voile: rgba(0, 0, 0, .55); --ombre: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .25);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--fond); color: var(--encre);
  font: 16px/1.55 var(--police); font-variant-numeric: tabular-nums;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
}
h1, h2, h3 { line-height: 1.2; margin: 0; font-weight: 700; }
h1 { font-family: var(--titre); font-size: 2.15rem; font-weight: 600; letter-spacing: .005em; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1rem; }
p { margin: 0 0 .75rem; }
a { color: var(--accent-fonce); }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--accent) 60%, transparent); outline-offset: 2px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.attente { padding: 2rem; color: var(--encre-douce); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  min-height: 40px; padding: .45rem .95rem; border-radius: var(--r);
  border: 1px solid var(--trait-fort); background: var(--surface); color: var(--encre);
  font: inherit; font-weight: 600; font-size: .95rem; text-decoration: none; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--encre-douce); }
.btn:disabled { opacity: .55; cursor: wait; }
.btn-principal { background: var(--accent); border-color: var(--accent); color: var(--sur-accent); }
.btn-principal:hover { background: var(--accent-fonce); border-color: var(--accent-fonce); }
.btn-danger { background: var(--rouge); border-color: var(--rouge); color: var(--sur-accent); }
.btn-large { width: 100%; min-height: 46px; font-size: 1rem; }
.btn-petit { min-height: 32px; padding: .2rem .6rem; font-size: .875rem; }
.btn-lien { background: none; border: 0; padding: .25rem 0; color: var(--accent-fonce); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.btn-icone { display: inline-grid; place-items: center; width: 40px; height: 40px; border: 0; background: none; border-radius: var(--r); color: inherit; font-size: 1.5rem; cursor: pointer; }
.btn-icone:hover { background: var(--menu); }
.btn-icone svg { width: 22px; height: 22px; }

/* ---------- Connexion ---------- */
.appli-connexion { min-height: 100vh; }
.connexion { min-height: 100vh; display: grid; grid-template-columns: 1.15fr minmax(340px, 460px); }
.connexion-marque {
  display: grid; place-items: center; padding: 3rem; position: relative; overflow: hidden;
  background: radial-gradient(120% 90% at 30% 20%, var(--surface) 0%, var(--menu) 70%);
}
.connexion-marque .logo-complet { width: min(380px, 70%); height: auto; }
.connexion-marque p { position: absolute; bottom: 2.5rem; left: 0; right: 0; text-align: center; color: var(--encre-douce); font-family: var(--titre); font-size: 1.35rem; font-style: italic; margin: 0; }
.connexion-form { align-self: center; padding: 3rem; display: grid; gap: 1.1rem; }
.connexion-form h1 { margin-bottom: .25rem; }
.alerte { background: var(--rouge-pale); color: var(--rouge); padding: .6rem .8rem; border-radius: var(--r); margin: 0; }
@media (max-width: 800px) {
  .connexion { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .connexion-marque { padding: 2rem 1rem 1.25rem; }
  .connexion-marque .logo-complet { width: 200px; }
  .connexion-marque p { display: none; }
  .connexion-form { padding: 1.5rem 1.25rem; align-self: start; }
}

/* Logo selon le thème */
.pour-sombre { display: none; }
:root[data-theme="sombre"] .pour-clair { display: none; }
:root[data-theme="sombre"] .pour-sombre { display: inline-block; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="clair"]) .pour-clair { display: none; }
  :root:not([data-theme="clair"]) .pour-sombre { display: inline-block; }
}

/* ---------- Structure ---------- */
.appli { display: grid; grid-template-columns: 236px 1fr; min-height: 100vh; }
.menu {
  position: sticky; top: 0; height: 100vh; overflow-y: auto; background: var(--menu);
  display: flex; flex-direction: column; padding: 1.25rem .75rem; border-right: 1px solid var(--trait);
}
.menu-marque { display: flex; align-items: center; gap: .75rem; padding: .25rem .5rem 1.5rem; color: var(--encre); text-decoration: none; }
.menu-marque img { width: 46px; height: 46px; }
.marque-texte { display: grid; line-height: 1; }
.marque-nom { font-family: var(--titre); font-size: 1.6rem; font-weight: 600; letter-spacing: .14em; }
.marque-sous { font-size: .62rem; letter-spacing: .42em; color: var(--accent); margin-top: .3rem; font-weight: 600; }
.theme { display: flex; gap: .25rem; margin-top: .75rem; }
.theme button { flex: 1; padding: .3rem .2rem; border: 1px solid var(--trait-fort); background: none; color: var(--encre-douce); border-radius: 6px; font: inherit; font-size: .78rem; cursor: pointer; }
.theme button[aria-pressed="true"] { background: var(--surface); color: var(--encre); border-color: var(--accent); }
.menu ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.menu a {
  display: flex; align-items: center; gap: .7rem; padding: .55rem .65rem; border-radius: var(--r);
  color: var(--encre); text-decoration: none; font-weight: 500;
}
.menu a svg { width: 20px; height: 20px; color: var(--encre-douce); flex: none; }
.menu a:hover { background: var(--survol); }
.menu a.actif { background: var(--surface); font-weight: 600; box-shadow: inset 3px 0 0 var(--accent), var(--ombre); }
.menu a.actif svg { color: var(--accent); }
.menu-profil { margin-top: auto; padding: 1rem .5rem 0; border-top: 1px solid var(--trait); display: grid; gap: .1rem; font-size: .875rem; }
.menu-profil span { color: var(--encre-douce); }
.menu-profil .btn-lien { justify-self: start; margin-top: .5rem; }
.barre-mobile { display: none; }
.voile { display: none; }
.contenu { padding: 2rem clamp(1rem, 3vw, 2.5rem) 4rem; min-width: 0; outline: none; max-width: 1280px; }

@media (max-width: 900px) {
  .appli { grid-template-columns: 1fr; }
  .barre-mobile {
    display: flex; align-items: center; gap: .5rem; position: sticky; top: 0; z-index: 20;
    padding: .4rem .75rem; background: var(--surface); border-bottom: 1px solid var(--trait);
  }
  .barre-titre { font-family: var(--titre); font-weight: 600; letter-spacing: .14em; font-size: 1.2rem; }
.barre-mobile img { width: 32px; height: 32px; }
  .menu { position: fixed; z-index: 40; left: 0; top: 0; width: 272px; transform: translateX(-100%); transition: transform .2s ease; box-shadow: var(--ombre); }
  .menu-ouvert .menu { transform: none; }
  .menu-ouvert .voile { display: block; position: fixed; inset: 0; z-index: 30; background: var(--voile); }
  .contenu { padding: 1.25rem 1rem 3rem; }
}
@media (prefers-reduced-motion: reduce) { .menu { transition: none; } }

/* ---------- En-tête de page ---------- */
.entete { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.entete p { color: var(--encre-douce); margin: .35rem 0 0; }
.actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.fil { font-size: .9rem; margin-bottom: .5rem; display: inline-block; }

/* ---------- Panneaux, onglets ---------- */
.panneau { background: var(--surface); border: 1px solid var(--trait); border-radius: var(--r); padding: 1.35rem 1.4rem; }
.panneau + .panneau { margin-top: 1rem; }
.panneau > h2 { margin-bottom: 1rem; }
.onglets { display: flex; gap: .25rem; border-bottom: 1px solid var(--trait); margin-bottom: 1rem; overflow-x: auto; scrollbar-width: thin; }
.onglets a, .onglets button {
  padding: .6rem .9rem; border: 0; background: none; font: inherit; color: var(--encre-douce); text-decoration: none; white-space: nowrap;
  border-bottom: 3px solid transparent; margin-bottom: -1px; cursor: pointer; font-weight: 600;
}
.onglets .actif { color: var(--encre); border-bottom-color: var(--accent); }
.onglets .compte { display: inline-block; min-width: 1.4rem; padding: 0 .35rem; margin-left: .35rem; border-radius: 999px; background: var(--menu); font-size: .78rem; text-align: center; }

/* ---------- Indicateurs d'accueil ---------- */
.indicateurs { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem; margin-bottom: 2rem; }
.indicateur { display: block; background: var(--surface); border: 1px solid var(--trait); border-radius: var(--r); padding: 1rem 1.1rem; text-decoration: none; color: inherit; }
.indicateur:hover { border-color: var(--trait-fort); }
.indicateur strong { display: block; font-family: var(--titre); font-size: 2.4rem; font-weight: 600; line-height: 1.05; }
.indicateur span { color: var(--encre-douce); }
.indicateur.alerte-rouge strong { color: var(--rouge); }
.indicateur.montant strong { color: var(--cafe); }
.grille-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(360px, 1fr)); gap: 1rem; }
@media (max-width: 500px) { .grille-2 { grid-template-columns: 1fr; } }

/* ---------- Tableaux ---------- */
.tableau-conteneur { overflow-x: auto; border: 1px solid var(--trait); border-radius: var(--r); background: var(--surface); }
table { width: 100%; border-collapse: collapse; font-size: .95rem; }
th, td { padding: .7rem .8rem; text-align: left; border-bottom: 1px solid var(--trait); vertical-align: middle; }
th { font-size: .82rem; color: var(--encre-douce); font-weight: 600; letter-spacing: .01em; background: var(--entete-tableau); white-space: nowrap; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.cliquable { cursor: pointer; }
tbody tr.cliquable:hover { background: var(--survol); }
td.nombre, th.nombre { text-align: right; white-space: nowrap; }
td a { font-weight: 600; text-decoration: none; }
td a:hover { text-decoration: underline; }
.secondaire { color: var(--encre-douce); font-size: .875rem; }

/* Étiquettes de statut */
.etiquette { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .8rem; font-weight: 600; background: var(--menu); color: var(--encre-douce); white-space: nowrap; }
.etiquette.brouillon { background: var(--menu); color: var(--encre-douce); }
.etiquette.emis, .etiquette.accepte { background: var(--accent-pale); color: var(--accent-fonce); }
.etiquette.refuse, .etiquette.retard, .etiquette.bloque { background: var(--rouge-pale); color: var(--rouge); }
.etiquette.transforme { background: var(--cafe-pale); color: var(--cafe); }
.etiquette.paye { background: var(--vert-pale); color: var(--vert); }
.etiquette.attention { background: var(--ambre-pale); color: var(--ambre); }

/* ---------- Barre de filtres ---------- */
.filtres { display: flex; flex-wrap: wrap; gap: .75rem; align-items: center; margin-bottom: 1rem; }
.filtres input[type=search] { flex: 1 1 260px; max-width: 420px; }

/* ---------- Formulaires ---------- */
input, select, textarea {
  width: 100%; min-height: 40px; padding: .45rem .65rem; border: 1px solid var(--trait-fort); border-radius: var(--r);
  background: var(--surface); color: var(--encre); font: inherit; font-size: 1rem;
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); outline: 2px solid color-mix(in srgb, var(--accent) 25%, transparent); outline-offset: 0; }
input[type=checkbox], input[type=radio] { width: auto; min-height: 0; accent-color: var(--accent); }
.champ { display: grid; gap: .3rem; align-content: start; }
.champ label { font-weight: 600; font-size: .9rem; }
.champ small { color: var(--encre-douce); }
.requis { color: var(--rouge); }
.formulaire { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 1rem 1.25rem; }
.champ-plein { grid-column: 1 / -1; }
.choix { display: flex; flex-wrap: wrap; gap: .5rem 1.25rem; }
.choix label { display: inline-flex; align-items: center; gap: .4rem; font-weight: 500; }
fieldset { border: 0; padding: 0; margin: 0; }
legend { font-weight: 600; font-size: .9rem; margin-bottom: .4rem; }

/* ---------- Fenêtres ---------- */
dialog.fenetre { border: 0; padding: 0; border-radius: 10px; width: min(560px, calc(100vw - 2rem)); max-height: calc(100vh - 2rem); box-shadow: 0 24px 70px rgba(0, 0, 0, .28); color: var(--encre); }
dialog.fenetre-large { width: min(860px, calc(100vw - 2rem)); }
dialog::backdrop { background: var(--voile); }
.fenetre-corps { display: flex; flex-direction: column; max-height: calc(100vh - 2rem); }
.fenetre-corps header { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 1rem 1.25rem .5rem; }
.fenetre-contenu { padding: .5rem 1.25rem 1rem; overflow-y: auto; }
.fenetre-corps footer { display: flex; justify-content: flex-end; flex-wrap: wrap; gap: .5rem; padding: .9rem 1.25rem; border-top: 1px solid var(--trait); background: var(--entete-tableau); }
.liste-choix { list-style: none; margin: .75rem 0 0; padding: 0; max-height: 50vh; overflow-y: auto; border: 1px solid var(--trait); border-radius: var(--r); }
.liste-choix button { display: block; width: 100%; text-align: left; padding: .6rem .8rem; border: 0; border-bottom: 1px solid var(--trait); background: none; font: inherit; cursor: pointer; }
.liste-choix li:last-child button { border-bottom: 0; }
.liste-choix button:hover, .liste-choix button:focus-visible { background: var(--accent-pale); }

/* ---------- Notifications ---------- */
#notifications { position: fixed; z-index: 100; right: 1rem; bottom: 1rem; display: grid; gap: .5rem; max-width: min(420px, calc(100vw - 2rem)); }
.notif { padding: .75rem 1rem; border-radius: var(--r); box-shadow: var(--ombre); background: var(--encre); color: var(--sur-accent); font-weight: 500; }
.notif-erreur { background: var(--rouge); }

/* ---------- États vides ---------- */
.vide { padding: 2.5rem 1rem; text-align: center; color: var(--encre-douce); display: grid; justify-items: center; gap: .5rem; }

/* ---------- Document de vente : la feuille ---------- */
.document-zone { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 1.25rem; align-items: start; }
@media (max-width: 1500px) {
  .document-zone { grid-template-columns: 1fr; }
  .document-zone .cote { order: -1; position: static; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); align-items: start; }
  .document-zone .cote .actions { display: flex; flex-wrap: wrap; }
  .document-zone .cote .actions .btn { width: auto; }
}
.feuille {
  position: relative; background: var(--surface); border: 1px solid var(--trait); border-radius: 4px;
  box-shadow: var(--ombre); padding: clamp(1rem, 3vw, 2.25rem); overflow: hidden;
}
.feuille-entete { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 1.25rem; margin-bottom: 1.5rem; }
.feuille-type { font-size: .95rem; color: var(--encre-douce); font-weight: 600; }
.feuille-numero { font-family: var(--titre); font-size: 2.3rem; font-weight: 600; letter-spacing: .01em; }
.feuille-numero.sans-numero { color: var(--encre-douce); font-weight: 500; font-size: 1.35rem; }
.feuille-client { min-width: 220px; max-width: 320px; padding: .75rem 1rem; border-left: 3px solid var(--accent); background: var(--accent-pale); }
.feuille-client a { font-weight: 700; font-size: 1.05rem; }
.bas-feuille { display: flex; flex-wrap: wrap; justify-content: space-between; align-items: flex-end; gap: 1.5rem; margin-top: 1.5rem; }
.tampon {
  display: inline-block; transform: rotate(-7deg); margin: 0 0 .5rem .5rem;
  border: 3px solid currentColor; border-radius: 6px; padding: .2rem .8rem;
  font-weight: 700; font-size: 1.15rem; letter-spacing: .08em; text-transform: uppercase; opacity: .85; pointer-events: none;
}
.tampon.brouillon { color: var(--encre-douce); border-style: dashed; }
.tampon.emis { color: var(--accent); }
.tampon { font-family: var(--titre); letter-spacing: .14em; }
.tampon.transforme { color: var(--cafe); }
.tampon.refuse, .tampon.annule { color: var(--rouge); }
.tampon.accepte { color: var(--vert); }
.verrou { display: flex; gap: .6rem; align-items: flex-start; padding: .7rem .9rem; border-radius: var(--r); background: var(--accent-pale); color: var(--accent-fonce); margin-bottom: 1.25rem; font-size: .95rem; }
.verrou svg { width: 20px; height: 20px; flex: none; margin-top: 2px; }
.lignes td input, .lignes td select { min-height: 36px; padding: .3rem .45rem; font-size: .95rem; }
.lignes td.col-designation { min-width: 260px; width: 100%; }
.lignes td.col-nb input { width: 80px; text-align: right; }
.lignes td.col-prix input { width: 104px; }
.lignes td.col-tva select { width: 150px; }
.lignes td, .lignes th { padding-left: .45rem; padding-right: .45rem; }
.lignes .ajout td { background: var(--accent-pale); }
.totaux { margin-left: auto; width: min(100%, 340px); display: grid; gap: .25rem; }
.totaux div { display: flex; justify-content: space-between; gap: 1rem; }
.totaux .ttc { border-top: 2px solid var(--encre); margin-top: .35rem; padding-top: .45rem; font-weight: 700; font-size: 1.2rem; }
.totaux .net { color: var(--cafe); font-weight: 700; font-size: 1.15rem; }
.mentions { margin-top: 1.5rem; font-size: .85rem; color: var(--encre-douce); white-space: pre-line; }
.cote { display: grid; gap: 1rem; position: sticky; top: 1rem; }
.cote .panneau { padding: 1rem; }
.cote h2 { font-size: 1rem; margin-bottom: .75rem; }
.cote .actions { display: grid; gap: .5rem; }
.cote .actions .btn { width: 100%; justify-content: flex-start; }
.cote dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .3rem .75rem; font-size: .9rem; }
.cote dt { color: var(--encre-douce); }
.cote dd { margin: 0; text-align: right; }
.historique { list-style: none; margin: 0; padding: 0; font-size: .875rem; display: grid; gap: .4rem; }
.historique li { display: flex; justify-content: space-between; gap: .5rem; }

/* ---------- Fiche ---------- */
.fiche-infos { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: .75rem 1.5rem; margin: 0; }
.fiche-infos dt { font-size: .85rem; color: var(--encre-douce); }
.fiche-infos dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }
.chiffres { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; }
.chiffres div { border-left: 3px solid var(--trait-fort); padding-left: .75rem; }
.chiffres strong { display: block; font-family: var(--titre); font-size: 1.7rem; font-weight: 600; }
.chiffres span { color: var(--encre-douce); font-size: .875rem; }
.chiffres .depasse { border-color: var(--rouge); }
.chiffres .depasse strong { color: var(--rouge); }

@media print {
  .menu, .barre-mobile, .cote, .actions, #notifications { display: none !important; }
  .appli { display: block; }
  .feuille { box-shadow: none; border: 0; }
}
.case { display: inline-flex; align-items: center; gap: .45rem; font-weight: 500; cursor: pointer; }
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (max-width: 900px) {
  .document-zone .cote { order: 1; }
  .lignes td:first-child { min-width: 180px; }
}
.connexion-form .aide { color: var(--encre-douce); margin: 0; }
.filtres select { width: auto; flex: 0 1 240px; }
@media (max-width: 600px) { .filtres select, .filtres input[type=search] { flex: 1 1 100%; max-width: none; } }
table:not(.lignes) td:first-child { white-space: nowrap; }
