
  :root{
    --ink:#1B2420; --paper:#FFFFFF; --accent:#3E8A70; --slate:#56615C; --hairline:#D5DDD8;
    --boxbg:#F6F8F6; --gL:#3E8A70; --gD:#093A2D; --gM:#0F5C46;
    --green:#0F7A3D; --greenBg:#E3F6EA; --red:#B91C1C; --redBg:#FCE8E8;
    --amber:#92610D; --amberBg:#FDF3DC;
    --sp-1:4px; --sp-2:8px; --sp-3:12px; --sp-4:16px; --sp-5:20px; --sp-6:28px; --sp-7:40px;
  }
  *{box-sizing:border-box;}
  body{margin:0; font-family:'Helvetica Neue',Arial,sans-serif; background:var(--boxbg); -webkit-text-size-adjust:100%; color:var(--ink); line-height:1.5;}
  button, select, input, textarea{font-family:inherit;}
  a{color:inherit;}

  /* ===================== CHROME DE L'APPLICATION ===================== */
  .app-header-sticky{position:sticky; top:0; z-index:200; box-shadow:0 2px 10px rgba(0,0,0,.06);}
  .appbar{
    display:flex; align-items:center; gap:14px; padding:12px 26px; flex-wrap:wrap;
    background:linear-gradient(90deg, var(--gL), var(--gM)); color:#fff;
  }
  .appbar .mark{width:36px; height:36px; border-radius:8px; overflow:hidden; flex-shrink:0; box-shadow:0 2px 8px rgba(0,0,0,.28);}
  .appbar .mark img{width:100%; height:100%; object-fit:cover; display:block;}
  .appbar h1{font-family:Georgia,serif; font-weight:700; font-size:18px; margin:0; letter-spacing:.4px;}
  .appbar .tag{font-size:9px; letter-spacing:2.5px; opacity:.85;}
  .appbar .spacer{flex:1;}
  .appbar .who{font-size:11.5px; opacity:.92; margin-right:10px;}
  .header-badge{display:inline-flex; align-items:center; justify-content:center; min-width:20px; height:20px;
    padding:0 6px; border-radius:10px; background:#FF5C5C; color:#fff; font-size:11px; font-weight:700;
    cursor:pointer; margin-right:12px; box-shadow:0 1px 4px rgba(0,0,0,.25);}
  .header-badge:hover{background:#FF3B3B;}
  .appbar button.logout{background:rgba(255,255,255,.16); border:none; color:#fff; padding:7px 14px;
    border-radius:6px; font-size:11px; font-weight:700; cursor:pointer;}
  .appbar button.logout:hover{background:rgba(255,255,255,.26);}

  .tabs{display:flex; gap:2px; background:#fff; border-bottom:1px solid var(--hairline); padding:0 22px; overflow-x:auto; position:relative;}
  .tabs button{padding:13px 16px; border:none; background:none; font-size:12.5px; font-weight:700;
    color:var(--slate); cursor:pointer; border-bottom:2.5px solid transparent; letter-spacing:.2px; white-space:nowrap;}
  .tabs button.active{color:var(--gM); border-bottom-color:var(--gM);}
  /* Indice visuel de defilement horizontal : une legere ombre portee interne
     apparait sur le bord des qu'il reste du contenu cache dans cette
     direction, et disparait une fois arrive au bout -- jamais affichee en
     permanence, pilotee par JS (initScrollFade) qui mesure le contenu
     reellement cache. Une ombre plutot qu'un degrade de couleur pleine :
     fonctionne sur n'importe quel fond sous-jacent, sombre ou clair. */
  .scroll-fade-right{position:relative;}
  .scroll-fade-right::after{content:""; position:absolute; top:0; right:0; bottom:0; width:14px;
    box-shadow:inset -14px 0 12px -12px rgba(0,0,0,.28);
    pointer-events:none; opacity:0; transition:opacity .18s ease; z-index:5;}
  .scroll-fade-right.has-more-right::after{opacity:1;}
  .scroll-fade-right::before{content:""; position:absolute; top:0; left:0; bottom:0; width:14px;
    box-shadow:inset 14px 0 12px -12px rgba(0,0,0,.28);
    pointer-events:none; opacity:0; transition:opacity .18s ease; z-index:5;}
  .scroll-fade-right.has-more-left::before{opacity:1;}
  .tabs button:hover{color:var(--ink);}
  .sync-badge{display:inline-flex; align-items:center; gap:6px; padding:5px 12px 5px 9px; border-radius:20px;
    font-size:11px; font-weight:700; letter-spacing:.15px; white-space:nowrap; margin-right:14px;
    background:rgba(255,255,255,.14); border:1px solid rgba(255,255,255,.22);
    box-shadow:0 1px 3px rgba(0,0,0,.12); transition:background .25s,border-color .25s,box-shadow .25s;}
  .sync-dot{width:8px; height:8px; border-radius:50%; flex-shrink:0; background:currentColor; position:relative;}
  .sync-dot::after{content:""; position:absolute; inset:-4px; border-radius:50%; background:currentColor; opacity:.35;}
  .sync-badge.is-live{background:rgba(184,255,203,.16); border-color:rgba(184,255,203,.4); color:#DFFFE8;
    box-shadow:0 1px 4px rgba(0,0,0,.14), 0 0 0 1px rgba(184,255,203,.08) inset;}
  .sync-badge.is-live .sync-dot{background:#4ADE80; box-shadow:0 0 5px rgba(74,222,128,.85);}
  .sync-badge.is-live .sync-dot::after{background:#4ADE80; animation:syncPulse 1.7s ease-out infinite;}
  .sync-badge.is-syncing .sync-dot{background:#FFE9B0; animation:syncSpin 1s linear infinite;}
  .sync-badge.is-syncing .sync-dot::after{display:none;}
  .sync-badge.is-warn{background:rgba(255,233,176,.14); border-color:rgba(255,233,176,.35); color:#FFE9B0;}
  .sync-badge.is-warn .sync-dot{background:#FFE9B0;}
  .sync-badge.is-warn .sync-dot::after{display:none;}
  .sync-badge.is-error{background:rgba(255,201,201,.14); border-color:rgba(255,201,201,.35); color:#FFC9C9;}
  .sync-badge.is-error .sync-dot{background:#FFC9C9;}
  .sync-badge.is-error .sync-dot::after{display:none;}
  .sync-badge.is-idle{display:none;}
  @keyframes syncPulse{0%{transform:scale(1); opacity:.55;} 100%{transform:scale(2.4); opacity:0;}}
  @keyframes syncSpin{0%{opacity:1;} 50%{opacity:.3;} 100%{opacity:1;}}
  @media (max-width:640px){
    .sync-badge{padding:5px 9px;}
    .sync-badge .sync-label{display:none;}
  }
  .journal-actions{display:flex; gap:8px; flex-wrap:wrap; margin-bottom:12px;}
  .journal-actions .btn{padding:7px 13px; font-size:11.5px;}
  .tabs .kbd{font-size:9px; opacity:.55; margin-left:4px; font-weight:400;}

  .view{padding:26px 32px; max-width:1320px; margin:0 auto;}
  .view h2{font-family:Georgia,serif; font-size:19px; margin:0 0 4px 0;}
  .view .sub{font-size:12px; color:var(--slate); margin-bottom:22px;}

  .card{background:#fff; border:1px solid var(--hairline); border-radius:10px; padding:20px; margin-bottom:20px;}
  .card h3{font-family:Georgia,serif; font-size:14.5px; margin:0 0 14px 0; display:flex; align-items:center; gap:8px;}

  .kpi-grid{display:grid; grid-template-columns:repeat(auto-fit,minmax(190px,1fr)); gap:14px; margin-bottom:22px;}
  .kpi{background:#fff; border:1px solid var(--hairline); border-radius:10px; padding:16px 18px;}
  .kpi .label{font-size:10px; letter-spacing:.6px; color:var(--slate); text-transform:uppercase; font-weight:700;}
  .kpi .val{font-size:25px; font-weight:700; margin:6px 0 2px 0; color:var(--ink);}
  .kpi .sub{font-size:10.5px; color:var(--slate);}
  .kpi.accent .val{color:var(--gM);}

  table.datatable{width:100%; border-collapse:collapse; font-size:12.5px;}
  table.datatable th{text-align:left; padding:9px 10px; background:var(--ink); color:#fff; font-size:10.5px;
    letter-spacing:.4px; text-transform:uppercase; font-weight:700; white-space:nowrap;}
  table.datatable td{padding:9px 10px; border-bottom:1px solid var(--hairline); color:var(--slate);}
  table.datatable tr:hover td{background:var(--boxbg); cursor:pointer;}
  table.datatable td.strong{color:var(--ink); font-weight:700;}
  .table-scroll{overflow-x:auto; position:relative;}

  .pill{display:inline-block; padding:3px 10px; border-radius:20px; font-size:10px; font-weight:700; letter-spacing:.3px;}
  .pill.paid{color:var(--green); background:var(--greenBg);}
  .pill.issued{color:var(--amber); background:var(--amberBg);}
  .pill.late{color:var(--red); background:var(--redBg);}

  .btn{padding:10px 18px; border:none; border-radius:7px; font-size:12px; font-weight:700; cursor:pointer;
    letter-spacing:.2px; transition:filter .15s;}
  .btn:hover{filter:brightness(1.07);}
  .btn.primary{background:linear-gradient(90deg,var(--gL),var(--gM)); color:#fff;}
  .btn.gold{background:var(--accent); color:#fff;}
  .btn.ghost{background:var(--boxbg); color:var(--ink); border:1px solid var(--hairline);}
  .btn.danger{background:var(--redBg); color:var(--red);}
  .btn:disabled{opacity:.5; cursor:not-allowed;}

  .field{margin-bottom:14px;}
  .field label{display:block; font-size:10.5px; font-weight:700; letter-spacing:.4px; color:var(--slate);
    text-transform:uppercase; margin-bottom:6px;}
  .field input[type=text], .field input[type=email], .field input[type=number], .field input[type=date],
  .field select, .field textarea{
    width:100%; padding:10px 11px; border:1px solid var(--hairline); border-radius:7px; font-size:13.5px;
    color:var(--ink); background:#fff;
  }
  .field input:focus, .field select:focus, .field textarea:focus{outline:2px solid var(--gM); outline-offset:1px;}
  .row2{display:grid; grid-template-columns:1fr 1fr; gap:14px;}
  .row2 > *{min-width:0;}
  .row3{display:grid; grid-template-columns:1fr 1fr 1fr; gap:14px;}
  .row3 > *{min-width:0;}
  /* top ajuste a la hauteur reelle de l'en-tete desormais fige (mesuree a
     103px sur desktop) + une petite marge de respiration -- une valeur
     fixe de 14px (celle d'origine, avant l'ajout de l'en-tete sticky)
     aurait fait passer la carte SOUS l'en-tete des le premier defilement,
     puisque les deux sont maintenant sticky simultanement. */
  .inv-preview-card{position:sticky; top:115px;}
  @media (max-width:640px){
    .row2, .row3{grid-template-columns:1fr;}
    /* Le formulaire et l'apercu de facture sont desormais empiles en une
       seule colonne sur mobile (regle ci-dessus) : plus de long contenu
       voisin a faire defiler pendant que l'apercu resterait fixe, donc le
       comportement "sticky" n'a plus d'utilite pratique ici et redevient un
       positionnement normal dans le flux. Placee apres la regle de base,
       dans l'ordre naturel du fichier -- pas besoin de !important. */
    .inv-preview-card{position:static;}
  }

  .banner{display:flex; align-items:center; gap:12px; padding:13px 18px; border-radius:8px; margin-bottom:18px;
    font-size:12.5px; border-left:4px solid var(--accent); background:#FDF3DC; color:#5A3E0A;}
  .banner button{margin-left:auto; flex-shrink:0;}
  .banner.info{border-left-color:var(--gM); background:#E3EFEA; color:#093A2D;}
  @media (max-width:640px){
    /* Le bouton de la banniere (flex-shrink:0, texte assez long comme
       "Marquer comme fait sans télécharger") ne peut pas retrecir sous sa
       largeur intrinseque : sur mobile, il passe a la ligne sous le
       message plutot que de forcer un debordement horizontal. Placee ici,
       apres la definition de base de .banner (ligne precedente) -- l'ordre
       compte en CSS a specificite egale, une media query placee avant la
       regle de base serait ecrasee par elle. */
    .banner{flex-wrap:wrap;}
    .banner button{margin-left:0; width:100%;}
  }

  .shortcuts{display:flex; flex-wrap:wrap; gap:10px; margin-top:6px;}
  .shortcuts .sc{display:flex; align-items:center; gap:7px; font-size:11.5px; color:var(--slate); background:var(--boxbg);
    padding:7px 12px; border-radius:7px; border:1px solid var(--hairline);}
  .shortcuts kbd{background:var(--ink); color:#fff; padding:2px 7px; border-radius:4px; font-size:10.5px; font-weight:700;}

  .modal-overlay{position:fixed; inset:0; background:rgba(10,15,25,.55); display:flex; align-items:center;
    justify-content:center; z-index:100; padding:20px;}
  .modal{background:#fff; border-radius:12px; max-width:960px; width:100%; max-height:92vh; overflow:auto;
    box-shadow:0 20px 60px rgba(0,0,0,.3);}
  .modal-head{display:flex; align-items:center; padding:16px 22px; border-bottom:1px solid var(--hairline);}
  .modal-head h3{margin:0; font-family:Georgia,serif; font-size:15px;}
  .modal-head .x{margin-left:auto; background:none; border:none; font-size:20px; cursor:pointer; color:var(--slate);}
  .modal-body{padding:22px;}

  .login-wrap{min-height:100vh; display:flex; align-items:center; justify-content:center; background:var(--boxbg);}
  .login-card{background:#fff; border:1px solid var(--hairline); border-radius:14px; padding:40px; width:380px;
    text-align:center; box-shadow:0 4px 24px rgba(10,20,40,.08);}
  .login-card .mark{width:56px; height:56px; border-radius:13px; overflow:hidden; margin:0 auto 16px auto;}
  .login-card .mark img{width:100%; height:100%; object-fit:cover;}
  .login-card h1{font-family:Georgia,serif; font-size:20px; margin:0 0 2px 0;}
  .login-card .tag{font-size:9.5px; letter-spacing:3px; color:var(--accent); font-weight:700; margin-bottom:24px;}
  .login-card input{width:100%; padding:13px; border:1px solid var(--hairline); border-radius:8px; font-size:20px;
    text-align:center; letter-spacing:10px; margin-bottom:14px;}
  .login-card .err{color:var(--red); font-size:11.5px; margin-bottom:10px; min-height:16px;}
  .login-card .note{font-size:10.5px; color:var(--slate); margin-top:18px; line-height:1.6;}
  .role-toggle{display:flex; gap:8px; margin-bottom:18px;}
  .role-toggle button{flex:1; padding:9px; border:1.5px solid var(--hairline); background:#fff; border-radius:7px;
    font-size:11.5px; font-weight:700; color:var(--slate); cursor:pointer;}
  .role-toggle button.active{border-color:var(--gM); background:#E3EFEA; color:var(--ink);}

  footer.app-footer{padding:16px 32px; font-size:10.5px; color:var(--slate); text-align:center;
    border-top:1px solid var(--hairline);}

  /* ===================== FACTURE — style verrouillé, ne pas modifier ===================== */
  #printArea{ position:absolute; left:-99999px; top:0; }
  .inv-sheet{ width:210mm; min-height:297mm; padding:14mm 14mm 10mm 14mm; position:relative;
    background:#fff; color:#1B2420; font-family:'Helvetica Neue',Arial,sans-serif;
    -webkit-print-color-adjust:exact; print-color-adjust:exact; }
  .inv-topbar{ height:5px; width:100%; position:absolute; top:0; left:0; }
  .inv-masthead{ display:flex; justify-content:space-between; align-items:flex-start; margin-top:6mm; }
  .inv-brand{ display:flex; align-items:flex-start; gap:4mm; }
  .inv-brand img.logo{ width:50mm; height:auto; display:block; }
  .inv-brand h1{ font-family:Georgia,'Times New Roman',serif; font-size:32px; letter-spacing:1.5px; margin:0;
    color:#1B2420; font-weight:700; }
  .inv-brand .baseline{ font-size:10.5px; letter-spacing:4px; color:#3E8A70; font-weight:700; margin-top:2px; }
  .inv-brand .meta{ margin-top:10px; font-size:11px; color:#56615C; line-height:1.75; }
  .inv-doc-title{ text-align:right; }
  .inv-doc-title .label{ font-family:Georgia,serif; font-size:24px; letter-spacing:3px; color:#1B2420; font-weight:700; }
  .inv-doc-title .num{ font-size:13px; color:#56615C; margin-top:5px; font-weight:500; }
  .inv-badge{ display:inline-block; margin-top:9px; padding:5px 14px; border-radius:20px; font-size:11px;
    font-weight:700; letter-spacing:.6px; line-height:1; }
  .inv-divider{ height:2px; background:#1B2420; margin:7mm 0 6mm 0; }
  .inv-parties{ display:flex; justify-content:space-between; gap:8mm; }
  .inv-party{ flex:1; border:1px solid #D5DDD8; border-radius:3px; overflow:hidden; }
  .inv-party .head{ background:linear-gradient(90deg,#3E8A70,#0F5C46); color:#fff; font-size:10px;
    letter-spacing:1.8px; font-weight:700; padding:6px 10px; line-height:1; }
  .inv-party .body{ padding:9px 10px 11px 10px; background:#F6F8F6; }
  .inv-party .name{ font-size:14.5px; font-weight:700; color:#1B2420; margin-bottom:4px; }
  .inv-party .line{ font-size:11px; color:#56615C; line-height:1.85; }
  .inv-party .line strong{ color:#1B2420; }
  table.inv-items{ width:100%; border-collapse:collapse; margin-top:7mm; font-size:11.5px; }
  table.inv-items thead th{ text-align:left; font-size:9.5px; letter-spacing:1.2px; color:#fff; text-transform:uppercase;
    background:linear-gradient(90deg,#3E8A70,#0F5C46); padding:8px 8px; line-height:1; }
  table.inv-items thead th.num{ text-align:right; }
  table.inv-items tbody td{ padding:11px 8px; border-bottom:1px solid #D5DDD8; vertical-align:top; }
  table.inv-items tbody td.num{ text-align:right; font-variant-numeric:tabular-nums; font-weight:600; }
  table.inv-items tbody .desc-title{ font-weight:700; color:#1B2420; font-size:12px; }
  table.inv-items tbody .desc-sub{ color:#56615C; font-size:10px; margin-top:3px; line-height:1.6; }
  .inv-lower{ display:flex; justify-content:space-between; gap:10mm; margin-top:6mm; }
  table.inv-paiement{ flex:1; border-collapse:collapse; font-size:10.5px; align-self:flex-start; }
  table.inv-paiement caption{ text-align:left; font-size:10px; letter-spacing:1.8px; font-weight:700; color:#fff;
    background:linear-gradient(90deg,#3E8A70,#0F5C46); padding:6px 10px; caption-side:top; line-height:1; }
  table.inv-paiement td{ padding:8px 10px; border:1px solid #D5DDD8; }
  table.inv-paiement td.label{ color:#56615C; background:#F6F8F6; }
  table.inv-paiement td.value{ font-weight:700; color:#1B2420; text-align:right; }
  .inv-totals{ width:68mm; font-size:11px; }
  .inv-totals .row{ display:flex; justify-content:space-between; padding:6px 4px; }
  .inv-totals .row.sub{ color:#56615C; }
  .inv-totals .row.total{ border-top:2px solid #1B2420; margin-top:5px; padding-top:9px; font-size:17px;
    font-weight:700; color:#1B2420; }
  .inv-lettres{ margin-top:5mm; padding:8px 12px; border:1px dashed #D5DDD8; border-radius:3px; font-size:10.5px;
    font-style:italic; color:#56615C; }
  .inv-lettres strong{ color:#1B2420; font-style:normal; }
  .inv-bottom{ display:flex; justify-content:space-between; align-items:flex-end; margin-top:8mm; }
  .inv-payment{ font-size:10.5px; color:#56615C; line-height:1.9; max-width:95mm; }
  .inv-payment .eyebrow{ font-size:9.5px; letter-spacing:1.8px; color:#3E8A70; font-weight:700; margin-bottom:5px; }
  .inv-payment strong{ color:#1B2420; }
  .inv-qr-box{ text-align:center; }
  .inv-qr-box img{ width:28mm; height:28mm; border:1.5px solid #1B2420; padding:3mm; border-radius:4px; }
  .inv-qr-box .cap{ font-size:8.5px; color:#56615C; letter-spacing:.6px; margin-top:5px; font-weight:600; }
  .inv-footer{ margin-top:10mm; padding-top:5mm; border-top:1px solid #D5DDD8; font-size:9px; color:#56615C;
    text-align:center; line-height:1.7; }
  .inv-footer .thanks{ font-family:Georgia,serif; font-style:italic; font-size:12px; color:#1B2420; margin-bottom:6px;
    font-weight:700; }

  .inv-preview-frame{ border:1px solid var(--hairline); border-radius:8px; overflow:hidden; background:#525659;
    padding:20px; display:flex; justify-content:flex-start; max-width:100%; }
  .inv-preview-frame .scale-wrap{ transform-origin:top left; }

  @media print{
    @page{ size:A4; margin:0; }
    body *{ visibility:hidden; }
    #printArea, #printArea *{ visibility:visible; }
    #printArea{ position:absolute; left:0; top:0; }
    .inv-sheet{ box-shadow:none; }
  }

/* ===================== ADDITIONS SIPED ===================== */
.appbar .mark{background:#fff; padding:3px;}
.appbar .mark img{object-fit:contain;}
.login-card .mark{background:#fff;}
.login-card .mark img{object-fit:contain;}
.login-card .logo-full{width:210px; max-width:80%; display:block; margin:0 auto 6px auto;}
.lines-head,.line-row{display:grid; grid-template-columns:minmax(0,3fr) 74px 130px 120px 34px; gap:8px; align-items:start;}
.lines-head{font-size:10px; font-weight:700; letter-spacing:.4px; color:var(--slate); text-transform:uppercase; margin-bottom:6px;}
.line-row{margin-bottom:10px; padding-bottom:10px; border-bottom:1px dashed var(--hairline);}
.line-row input,.line-row textarea{width:100%; padding:9px 10px; border:1px solid var(--hairline); border-radius:7px; font-size:13px; color:var(--ink); background:#fff; font-family:inherit;}
.line-row input:focus,.line-row textarea:focus{outline:2px solid var(--gM); outline-offset:1px;}
.line-row textarea{margin-top:6px; font-size:12px; resize:vertical; min-height:36px;}
.line-row .ltot{padding:9px 4px; font-weight:700; font-size:13px; text-align:right; color:var(--ink); white-space:nowrap;}
.line-row .lrm{border:none; background:var(--redBg); color:var(--red); border-radius:7px; height:36px; cursor:pointer; font-weight:700;}
.lines-total{display:flex; justify-content:flex-end; gap:18px; font-size:12.5px; color:var(--slate); margin:6px 0 2px 0;}
.lines-total strong{color:var(--ink);}
@media (max-width:760px){
  .lines-head{display:none;}
  .line-row{grid-template-columns:1fr 1fr; }
  .line-row > :first-child{grid-column:1 / -1;}
  .line-row .ltot{text-align:left;}
}
.toast-zone{position:fixed; right:18px; bottom:18px; z-index:400; display:flex; flex-direction:column; gap:8px;}
.toast{background:var(--ink); color:#fff; padding:11px 16px; border-radius:8px; font-size:12.5px; box-shadow:0 6px 24px rgba(0,0,0,.25); max-width:340px;}
.toast.ok{background:var(--green);} .toast.ko{background:var(--red);}
.hint{font-size:11.5px; color:var(--slate); line-height:1.6;}
.code{font-family:ui-monospace,Menlo,Consolas,monospace; font-size:11.5px; background:var(--boxbg); border:1px solid var(--hairline); border-radius:6px; padding:2px 6px;}
.toolbar{display:flex; gap:10px; flex-wrap:wrap; align-items:center; margin-bottom:14px;}
.toolbar .field{margin:0; min-width:160px; flex:1;}
.pill.sent{color:#1D4ED8; background:#E5EEFF;} .pill.relance{color:#B45309; background:#FDEEDC;}
.empty{ text-align:center; color:var(--slate); padding:26px;}
.num-r{text-align:right; white-space:nowrap;}
.offline-ribbon{background:var(--amberBg); color:var(--amber); font-size:11.5px; text-align:center; padding:6px; font-weight:700;}
.modal.sm{max-width:560px;}
