/* ==========================================================================
   Nexus Facturation — Base UI (Dark default + Light theme)
   Theme switch: set data-theme="light" on <html> (recommended).
   ========================================================================== */

/* ------------------------------ Theme tokens ------------------------------ */
:root{
  /* Dark (default) */
  --bg: #0b0f17;
  --bg-grad-1: rgba(138,180,255,.20);
  --bg-grad-2: rgba(46,229,157,.14);

  --panel: rgba(255,255,255,.06);
  --panel-2: rgba(255,255,255,.10);
  --stroke: rgba(255,255,255,.16);
  --stroke-2: rgba(255,255,255,.24);

  --text: rgba(255,255,255,.96);
  --muted: rgba(255,255,255,.72);
  --link: #8ab4ff;

  --ok: #2ee59d;
  --warn: #ffd166;
  --danger: #ff5c5c;

  --shadow: 0 10px 30px rgba(0,0,0,.35);
  --r: 16px;

  --focus: rgba(138,180,255,.55);

  --aside-bg: rgba(0,0,0,.25);
  --header-bg: rgba(11,15,23,.55);

  --input-bg: rgba(0,0,0,.24);
  --btn-bg: rgba(255,255,255,.05);
  --btn-bg-hover: rgba(255,255,255,.08);

  --nav-hover: rgba(255,255,255,.06);
  --nav-active: rgba(138,180,255,.12);
  --nav-active-stroke: rgba(138,180,255,.22);

  --row-hover: rgba(255,255,255,.03);

  /* Socle visuel V1 — layout / surfaces / layers */
  --layout-content-max: 1480px;
  --layout-sidebar: 260px;
  --layout-page-x: 24px;
  --layout-page-y: 18px;

  --surface-page: var(--bg);
  --surface-card: var(--panel);
  --surface-raised: var(--panel-2);
  --border-subtle: var(--stroke);
  --border-strong: var(--stroke-2);
  --text-primary: var(--text);
  --text-secondary: var(--muted);
  --text-disabled: rgba(255,255,255,.78);

  --z-base: 0;
  --z-header: 100;
  --z-dropdown: 400;
  --z-overlay: 700;
  --z-modal: 800;
  --z-toast: 900;

  /* UI V2 — échelle commune : rythme, contrôles, surfaces et états */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;

  /* V4 — design system : typographie, rayons et cibles tactiles. */
  --font-ui: "Inter", "Segoe UI Variable", "Segoe UI", "Noto Sans", system-ui, -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", "Courier New", monospace;
  --text-xs: 12px;
  --text-sm: 13px;
  --text-md: 14px;
  --text-lg: 16px;
  --text-xl: 18px;
  --text-2xl: 24px;
  --leading-tight: 1.25;
  --leading-ui: 1.4;
  --leading-copy: 1.55;
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;
  --radius-sm: 10px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-pill: 999px;
  --touch-target-min: 44px;

  --control-h: 40px;
  --control-h-sm: 34px;
  --control-radius: var(--radius-md);

  --surface-faint: rgba(255,255,255,.02);
  --surface-subtle: rgba(255,255,255,.03);
  --surface-hover: rgba(255,255,255,.06);
  --surface-solid: rgba(255,255,255,.10);
  --surface-paper: #fff;
  --surface-paper-soft: rgba(255,255,255,.92);
  --surface-paper-strong: rgba(255,255,255,.96);
  --text-on-paper: #111;
  --border-faint: rgba(255,255,255,.08);
  --border-soft: rgba(255,255,255,.10);
  --overlay-backdrop: rgba(0,0,0,.55);
  --overlay-backdrop-strong: rgba(3,7,18,.62);
  --overlay-shadow: 0 18px 60px rgba(0,0,0,.45);
  --floating-shadow: 0 18px 46px rgba(0,0,0,.30);
  --sticky-shadow: 0 -12px 30px rgba(0,0,0,.10);
  --control-thumb: #fff;
  --control-thumb-shadow: 0 1px 4px rgba(0,0,0,.22);
  --scroll-track: rgba(255,255,255,.035);
  --scroll-thumb: rgba(138,180,255,.42);
  --scroll-thumb-hover: rgba(138,180,255,.62);
  --pdf-stage: #525659;
  --signature-canvas-border: #ccc;
  --signature-canvas-shadow: inset 0 0 10px rgba(0,0,0,.10);

  --accent-soft: rgba(138,180,255,.12);
  --accent-medium: rgba(138,180,255,.18);
  --accent-border: rgba(138,180,255,.28);
  --ok-soft: rgba(46,229,157,.12);
  --ok-border: rgba(46,229,157,.26);
  --warn-soft: rgba(255,209,102,.14);
  --warn-border: rgba(255,209,102,.26);
  --danger-soft: rgba(255,92,92,.12);
  --danger-border: rgba(255,92,92,.26);
  --loading-dot: rgba(255,255,255,.45);

  --kpi-glow: radial-gradient(500px 120px at 20% 0%, rgba(138,180,255,.18), transparent 55%),
              radial-gradient(500px 120px at 80% 0%, rgba(46,229,157,.10), transparent 55%);
  --totals-fade: linear-gradient(to top, rgba(0,0,0,.20), transparent);
}

/* Light theme override */
[data-theme="light"]{
  --bg: #f6f7fb;
  --bg-grad-1: rgba(37,87,255,.10);
  --bg-grad-2: rgba(10,143,91,.08);

  --panel: rgba(0,0,0,.03);
  --panel-2: rgba(0,0,0,.06);
  --stroke: rgba(0,0,0,.13);
  --stroke-2: rgba(0,0,0,.20);

  --text: rgba(0,0,0,.92);
  --muted: rgba(0,0,0,.64);
  --link: #2557ff;

  --ok: #0a8f5b;
  --warn: #b07a00;
  --danger: #d12b2b;

  --shadow: 0 10px 28px rgba(0,0,0,.10);

  --focus: rgba(37,87,255,.45);

  --aside-bg: rgba(255,255,255,.75);
  --header-bg: rgba(246,247,251,.80);

  --input-bg: rgba(255,255,255,.98);
  --btn-bg: rgba(255,255,255,.75);
  --btn-bg-hover: rgba(255,255,255,.95);

  --nav-hover: rgba(0,0,0,.04);
  --nav-active: rgba(37,87,255,.10);
  --nav-active-stroke: rgba(37,87,255,.20);

  --row-hover: rgba(0,0,0,.025);
  --text-disabled: rgba(0,0,0,.72);

  --surface-faint: rgba(0,0,0,.01);
  --surface-subtle: rgba(0,0,0,.02);
  --surface-hover: rgba(0,0,0,.04);
  --surface-solid: rgba(0,0,0,.06);
  --surface-paper-soft: rgba(255,255,255,.95);
  --surface-paper-strong: rgba(255,255,255,.98);
  --border-faint: rgba(0,0,0,.08);
  --border-soft: rgba(0,0,0,.10);
  --overlay-backdrop: rgba(0,0,0,.40);
  --loading-dot: rgba(0,0,0,.35);

  --accent-soft: rgba(37,87,255,.10);
  --accent-medium: rgba(37,87,255,.12);
  --accent-border: rgba(37,87,255,.22);
  --scroll-track: rgba(0,0,0,.035);
  --scroll-thumb: rgba(37,87,255,.30);
  --scroll-thumb-hover: rgba(37,87,255,.48);
  --ok-soft: rgba(10,143,91,.10);
  --ok-border: rgba(10,143,91,.24);
  --warn-soft: rgba(176,122,0,.10);
  --warn-border: rgba(176,122,0,.24);
  --danger-soft: rgba(209,43,43,.10);
  --danger-border: rgba(209,43,43,.24);

  --kpi-glow: radial-gradient(500px 120px at 20% 0%, rgba(37,87,255,.10), transparent 55%),
              radial-gradient(500px 120px at 80% 0%, rgba(10,143,91,.08), transparent 55%);
  --totals-fade: linear-gradient(to top, rgba(255,255,255,.90), transparent);
}

/* ------------------------------ Base reset -------------------------------- */
*{ box-sizing: border-box; }
html, body{ min-height: 100vh; } /* Remplacé height: 100% par min-height */

body{
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--text-md);
  font-weight: var(--weight-regular);
  line-height: var(--leading-copy);
  letter-spacing: -0.01em;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
  color: var(--text);
  /* Ajout d'un 3ème gradient pour le bas et d'un attachment fixed */
  background:
  radial-gradient(1200px 600px at 20% 0%, var(--bg-grad-1), transparent 55%),
  radial-gradient(900px 700px at 80% 20%, var(--bg-grad-2), transparent 55%),
  radial-gradient(1000px 600px at 50% 100%, var(--bg-grad-1), transparent 55%),
  var(--bg);
  background-attachment: fixed;
}

a{ color: var(--link); text-decoration: none; }
a:hover{ text-decoration: underline; }

img{ max-width: 100%; height: auto; }

/* Focus accessible */
:focus{ outline: none; }
:focus-visible{
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 10px;
}

/* ------------------------------ Layout shell ------------------------------ */
.container{
  width: 100%;
  max-width: var(--layout-content-max);
  margin: 0 auto;
  padding: var(--layout-page-y) var(--layout-page-x);
}

.app{
  display: grid;
  grid-template-columns: var(--layout-sidebar) minmax(0, 1fr);
  min-height: 100vh;
}

.app-aside{
  position: sticky;
  top: 0;
  height: 100vh;
  align-self: start; /* Corrige le bug du sticky dans la grille */
  overflow-y: auto;  /* Permet de scroller dans le menu si l'écran est petit */
  border-right: 1px solid var(--stroke);
  background: var(--aside-bg);
  backdrop-filter: blur(10px);
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.app-main{ min-width: 0; }

.app-header{
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--stroke);
}

.header-flex{
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.h1{
  margin: 0;
  font-size: var(--text-xl);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: -0.2px;
}

.app-content{
  padding-top: 16px;
  padding-bottom: 40px;
}

/* Largeur de travail volontairement resserrée pour les formulaires longs.
   Le choix vit dans le socle afin d'éviter les max-width page par page. */
.workspace--focused{
  width:100%;
  max-width:1220px;
  margin-inline:auto;
}

/* ------------------------------ Brand / Nav ------------------------------- */
.aside-top{ padding: 4px; }

.brand{
  display: flex;
  gap: 12px;
  align-items: center;
  text-decoration: none;
  color: var(--text);
}

.brand-logo{
  width: 44px;
  height: 44px;
  border-radius: var(--control-radius);
  background: var(--panel);
  border: 1px solid var(--stroke);
  padding: 6px;
}

.brand-name{
  font-weight: var(--weight-bold);
  letter-spacing: -0.2px;
  line-height: var(--leading-tight);
}

.brand-sub{
  color: var(--muted);
  font-size: var(--text-xs);
  line-height: var(--leading-ui);
  margin-top: 2px;
}

.nav{
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.nav-item{
  display: flex;
  align-items: center;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--text);
  border: 1px solid transparent;
  text-decoration: none;
  user-select: none;
}

.nav-item:hover{
  background: var(--nav-hover);
  border-color: rgba(255,255,255,.08);
}

[data-theme="light"] .nav-item:hover{
  border-color: rgba(0,0,0,.08);
}

.nav-item.active{
  background: var(--nav-active);
  border-color: var(--nav-active-stroke);
}

.aside-menu{
  min-height:0;
  flex:1 1 auto;
  display:flex;
  flex-direction:column;
  gap:16px;
}

.mobile-menu-toggle{
  display:none;
}

.aside-foot{
  margin-top: auto;
  display: flex;
  justify-content: flex-start;
}

.auth-session{
  display:flex;
  flex-direction:column;
  gap:8px;
  width:100%;
}
.auth-logout-form{ margin:0; }
.auth-logout-form .btn{ width:100%; }

.pill{
  font-size: var(--text-xs);
  color: var(--muted);
  border: 1px solid var(--stroke);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(255,255,255,.04);
}

[data-theme="light"] .pill{
  background: rgba(0,0,0,.02);
}

/* ------------------------------ Page chrome ------------------------------- */
.page-header{
  display:flex;
  align-items:flex-start;
  justify-content:space-between;
  gap:16px;
}

.page-title{
  margin:0;
  font-size:var(--text-2xl);
  font-weight:var(--weight-bold);
  line-height:var(--leading-tight);
  letter-spacing:-.4px;
}

.page-subtitle{
  margin:6px 0 0;
  max-width:760px;
  color:var(--muted);
  font-size:var(--text-md);
  line-height:var(--leading-copy);
}

.page-actions{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:10px;
  flex-wrap:wrap;
}

.toolbar{
  display:flex;
  align-items:flex-end;
  gap:12px;
  flex-wrap:wrap;
}
.toolbar--center{ align-items:center; }
.toolbar .grow{
  flex:1 1 280px;
  min-width:240px;
}

@media (max-width:768px){
  .page-header{
    flex-direction:column;
    align-items:stretch;
  }
  .page-actions{ justify-content:flex-start; }
  .page-actions--stretch-md{ width:100%; }
  .page-actions--stretch-md .btn{ width:100%; }
  .toolbar--stack-md{
    align-items:stretch;
    flex-direction:column;
  }
  .toolbar--stack-md > .field,
  .toolbar--stack-md > .input,
  .toolbar--stack-md > select,
  .toolbar--stack-md > .btn{
    width:100%;
    min-width:0;
  }
}

@media (max-width:560px){
  .page-actions{ width:100%; }
  .page-actions .btn{ flex:1 1 auto; }
  .page-actions--stack-sm{ display:grid; }
  .page-actions--stack-sm .btn{ width:100%; }
  .toolbar{ align-items:stretch; }
  .toolbar > .field,
  .toolbar > .input,
  .toolbar > select,
  .toolbar > .btn{
    width:100%;
    min-width:0;
  }
  .toolbar .grow{ min-width:0; }
  .pager--responsive{ flex-wrap:wrap; }
  .pager--responsive > .btn{ flex:1 1 40%; }
}

/* ------------------------------ List system V4.1 -------------------------- */
.list-page{
  display:flex;
  flex-direction:column;
  gap:var(--space-4);
}
.list-header{ gap:var(--space-5); }
.list-header-actions{ flex:0 0 auto; }
.list-card{ overflow:hidden; }
.list-toolbar{
  gap:var(--space-3);
  padding:var(--space-4);
  border-bottom:1px solid var(--stroke);
}
.list-toolbar--standalone{ border-bottom:0; }
.list-toolbar > .field:not(.grow){ flex:0 1 220px; min-width:160px; }
.list-toolbar > .field.grow{ flex:1 1 320px; min-width:240px; }
.list-table-wrap{ margin:0; }
.list-footer{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:var(--space-3);
  padding:var(--space-3) var(--space-4);
  border-top:1px solid var(--stroke);
}
.list-pager{ margin-top:0; }
.loading-state{
  padding:var(--space-5) var(--space-4);
  color:var(--muted);
  text-align:center;
  font-size:var(--text-md);
}
@media (max-width:768px){
  .list-toolbar.toolbar{
    align-items:stretch;
    flex-direction:column;
  }
  /* En colonne, le flex-basis desktop devient une hauteur. On le neutralise
     explicitement pour éviter les filtres de 220/320 px de haut sur mobile. */
  .list-toolbar > .field:not(.grow),
  .list-toolbar > .field.grow{
    flex:0 0 auto;
  }
  .list-toolbar > .field,
  .list-toolbar > .input,
  .list-toolbar > select,
  .list-toolbar > .btn{
    width:100%;
    min-width:0;
  }
  .list-toolbar .grow{ min-width:0; }
}
@media (max-width:560px){
  .list-toolbar{
    gap:var(--space-3);
    padding:var(--space-3);
  }
  .list-header-actions{ width:100%; }
  .list-header-actions .btn{ min-width:0; }
  .list-footer{
    align-items:stretch;
    flex-direction:column;
  }
  .list-footer .pager{ width:100%; }
}

/* ----------------------- Actions de tableau partagées --------------------- */
/*
 * Les actions de ligne restent sur une seule ligne. Les tableaux larges sont
 * déjà protégés par table-scroll : on fait défiler le tableau, pas les boutons.
 * Les anciens noms de classes restent supportés comme alias de transition.
 */
.table-actions,
.devis .row-actions,
.factures-table-card .factures-actions,
.drafts-table .draft-row-actions{
  display:flex;
  align-items:center;
  justify-content:flex-end;
  gap:8px;
  flex-wrap:nowrap;
  white-space:nowrap;
}

.table-action-cell,
.contracts-card .contracts-row-actions,
.purchases-table-card .purchases-actions{
  white-space:nowrap;
}

/* ------------------------------ Surfaces ---------------------------------- */
.card{
  background: var(--panel);
  border: 1px solid var(--stroke);
  border-radius: var(--r);
  box-shadow: var(--shadow);
}

.card.soft{
  background: rgba(255,255,255,.03);
  box-shadow: none;
}

[data-theme="light"] .card.soft{
  background: rgba(0,0,0,.02);
}

/* Carte interne commune : surface secondaire sans ombre. */
.card.inner{
  padding:12px;
  box-shadow:none;
  background:var(--surface-subtle);
}

/* ------------------------------ Buttons ----------------------------------- */
.btn{
  appearance: none;
  border: 1px solid var(--stroke);
  background: var(--btn-bg);
  color: var(--text);
  min-height: var(--control-h);
  height: var(--control-h);
  padding: 0 var(--space-3);
  border-radius: var(--control-radius);
  cursor: pointer;
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: 1;
  user-select: none;
}

.btn:hover{ background: var(--btn-bg-hover); }

.btn:active{ transform: translateY(0.5px); }

.btn-primary{
  background: rgba(138,180,255,.18);
  border-color: rgba(138,180,255,.30);
}

.btn-primary:hover{ background: rgba(138,180,255,.24); }

[data-theme="light"] .btn-primary{
  background: rgba(37,87,255,.12);
  border-color: rgba(37,87,255,.22);
}

[data-theme="light"] .btn-primary:hover{
  background: rgba(37,87,255,.16);
}


.btn-success{
  color:var(--ok);
  border-color:var(--ok-border);
  background:var(--ok-soft);
}
.btn-danger,
.btn.danger{
  color:var(--danger);
  border-color:var(--danger-border);
  background:var(--danger-soft);
}
.btn-ghost,
.btn.ghost{ background:transparent; }
.btn-sm,
.btn-xs,
.btn-small{
  min-height:var(--control-h-sm);
  height:var(--control-h-sm);
  padding-inline:var(--space-3);
  font-size:var(--text-xs);
}

/* ------------------------------ Forms / Inputs ---------------------------- */
.field{
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.label,
.field-group > label,
.client-selector > label{
  margin: 0;
  color: var(--text);
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  line-height: var(--leading-ui);
}

.hint,
.field-help{
  margin-top: 3px;
  color: var(--muted);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
}

.input,
.textarea{
  width: 100%;
  border-radius: var(--control-radius);
  border: 1px solid var(--stroke-2);
  background: var(--input-bg);
  color: var(--text);
  font-family: inherit;
  font-size: var(--text-md);
  font-weight: var(--weight-medium);
}

.input{
  height: var(--control-h);
  padding: 0 var(--space-3);
}

textarea.input,
textarea.textarea{
  height: auto;
  padding: 9px 10px;
  line-height: 1.45;
  resize: none;
  overflow-y: hidden;
}

.input::placeholder,
.textarea::placeholder{ color: var(--muted); }
select.input{ padding-right: 30px; }

/* Rationalisation UI V3.4 — variantes de formulaires partagées. */
.form-grid{
  display:grid;
  gap:14px 16px;
}
.form-grid--2{ grid-template-columns:repeat(2,minmax(0,1fr)); }
.form-grid--3{ grid-template-columns:repeat(3,minmax(0,1fr)); }
.field--full{ grid-column:1 / -1; }
.field--sm{ min-width:180px; }
.field--min-220{ min-width:220px; }
.input-lg{ height:44px; font-size:14px; }
.textarea--compact{ min-height:72px; }
.textarea--md{ min-height:80px; }
.textarea--lg{ min-height:120px; }

@media (max-width:1024px){
  .form-grid--stack-lg,
  .grid-2--stack-lg{ grid-template-columns:1fr; }
}
@media (max-width:768px){
  .form-grid--3{ grid-template-columns:repeat(2,minmax(0,1fr)); }
}
@media (max-width:560px){
  .form-grid--3{ grid-template-columns:1fr; }
  .field--full{ grid-column:auto; }
  .field--sm,
  .field--min-220{ min-width:0; }
}

/* ------------------------------ Tables ------------------------------------ */
.table{
  width: 100%;
  border-collapse: collapse;
  overflow: hidden;
  border-radius: var(--radius-md);
  border: 1px solid rgba(255,255,255,.06);
}

[data-theme="light"] .table{
  border-color: rgba(0,0,0,.06);
}

.table th, .table td{
  padding: var(--space-3) var(--space-3);
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-size: var(--text-sm);
  line-height: var(--leading-ui);
  vertical-align: middle;
}

[data-theme="light"] .table th,
[data-theme="light"] .table td{
  border-bottom-color: rgba(0,0,0,.08);
}

.table th{
  text-align: left;
  color: var(--muted);
  font-weight:var(--weight-semibold);
  letter-spacing: -0.1px;
}

.table tr:hover td{ background: var(--row-hover); }

.table .right{ text-align: right; }

/* Conteneur de débordement horizontal commun aux tableaux larges. */
.table-scroll{
  max-width:100%;
  overflow:auto;
  scrollbar-width:thin;
  scrollbar-color:var(--scroll-thumb) var(--scroll-track);
}
.table-scroll::-webkit-scrollbar{ width:8px; height:8px; }
.table-scroll::-webkit-scrollbar-track{
  background:var(--scroll-track);
  border-radius:var(--radius-pill);
}
.table-scroll::-webkit-scrollbar-thumb{
  min-width:42px;
  border:2px solid transparent;
  border-radius:var(--radius-pill);
  background:var(--scroll-thumb);
  background-clip:padding-box;
}
.table-scroll::-webkit-scrollbar-thumb:hover{
  background:var(--scroll-thumb-hover);
  background-clip:padding-box;
}
.table--wide-md{min-width:720px;}

/* Variantes de tableaux de listes : comportement commun, sans logique métier. */
.table-scroll--framed{
  border:1px solid var(--stroke);
  border-radius:var(--r);
}
.table--wide{
  width:max-content;
  min-width:100%;
}
.table--flush{
  margin:0;
  border:0;
}
.table--sticky-head thead th{
  position:sticky;
  top:0;
  z-index:2;
  background:var(--panel-2);
}
[data-theme="light"] .table--sticky-head thead th{
  background:var(--surface-paper-soft);
}
.table--edge-padded th:first-child,
.table--edge-padded td:first-child{ padding-left:20px; }
.table--edge-padded th:last-child,
.table--edge-padded td:last-child{ padding-right:20px; }

@media (max-width:1024px){
  .table--wide-md{
    width:max-content;
    min-width:100%;
  }
}

/* ------------------------------ Shared content states ---------------------- */
.empty-state{
  display:grid;
  justify-items:center;
  gap:var(--space-1);
  margin:var(--space-4);
  padding:var(--space-8) var(--space-4);
  border:1px dashed var(--stroke);
  border-radius:var(--radius-md);
  background:var(--surface-faint);
  color:var(--muted);
  text-align:center;
  font-size:var(--text-md);
  line-height:var(--leading-copy);
}
.empty-state--compact{
  margin:var(--space-3) 0 0;
  padding:var(--space-4);
}
.empty-state__title{
  color:var(--text);
  font-size:var(--text-md);
  font-weight:var(--weight-semibold);
  line-height:var(--leading-ui);
}
.empty-state__text{
  max-width:560px;
  color:var(--muted);
  font-size:var(--text-sm);
  line-height:var(--leading-copy);
}
.empty-state[hidden]{ display:none; }

/* Alias transitoires hors listes : à supprimer avec les lots V4.2/V4.3. */
.empty,
.drafts-empty,
.contracts-state{
  margin:var(--space-3) 0 0;
  padding:var(--space-6) var(--space-4);
  border:1px dashed var(--stroke);
  border-radius:var(--radius-md);
  background:var(--surface-faint);
  color:var(--muted);
  text-align:center;
  font-size:var(--text-md);
  line-height:var(--leading-copy);
}
.empty[hidden],.drafts-empty[hidden],.contracts-state[hidden]{ display:none; }

/* ------------------------------ Shared UI V2 ------------------------------ */
.badge{
  display:inline-flex;
  align-items:center;
  min-height:22px;
  padding:3px 9px;
  border:1px solid var(--stroke);
  border-radius:var(--radius-pill);
  background:var(--surface-subtle);
  color:var(--text);
  font-size:var(--text-xs);
  font-weight:var(--weight-semibold);
  line-height:1;
}
.badge--info{ color:var(--link); border-color:var(--accent-border); background:var(--accent-soft); }
.badge--ok{ color:var(--ok); border-color:var(--ok-border); background:var(--ok-soft); }
.badge--warn{ color:var(--warn); border-color:var(--warn-border); background:var(--warn-soft); }
.badge--danger{ color:var(--danger); border-color:var(--danger-border); background:var(--danger-soft); }
.badge--soft{ opacity:.9; }
.badge--md{ font-size:var(--text-xs); }
.badge--compact{ font-size:var(--text-xs); text-transform:uppercase; letter-spacing:.035em; }
.badge--contract{ text-transform:capitalize; font-weight:var(--weight-semibold); }

/* Alias d'états historiques centralisés : mêmes classes de données, un seul propriétaire CSS. */
.badge.brouillon{ opacity:.82; }
.badge.actif,
.badge.signe{ color:var(--ok); border-color:var(--ok-border); background:var(--ok-soft); }
.badge.en_signature{ color:var(--warn); border-color:var(--warn-border); background:var(--warn-soft); }
.badge.resilie{ color:var(--danger); border-color:var(--danger-border); background:var(--danger-soft); }
.badge-payee,
.badge-sent{ color:var(--ok); }
.badge-emise{ color:var(--link); }
.badge-partiel,
.badge-due,
.badge-brouillon{ color:var(--warn); }
.badge-annule{ color:var(--danger); }
.badge-unsent{ color:var(--muted); }

.api-pill{
  display:inline-flex;
  align-items:center;
  gap:8px;
  min-height:34px;
  padding:7px 10px;
  border:1px solid var(--stroke);
  border-radius:var(--radius-pill);
  background:var(--surface-subtle);
  color:var(--muted);
}
.api-pill .dot{
  width:10px;
  height:10px;
  border-radius:50%;
  background:var(--loading-dot);
}
.api-pill .dot.load{ background:var(--warn); }
.api-pill .dot.ok{ background:var(--ok); }
.api-pill .dot.err{ background:var(--danger); }

.pager{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  margin-top:10px;
}
.pager-mid{
  display:flex;
  align-items:baseline;
  gap:8px;
}
.pager--inline{
  margin-top:0;
  justify-content:flex-end;
}
@media (max-width:560px){
  .pager--inline{ justify-content:space-between; }
}

.grid-2{
  display:grid;
  grid-template-columns:repeat(2,minmax(0,1fr));
  gap:12px;
}
.grid-2.roomy{ gap:16px; }
.grid-span-2{ grid-column:1 / -1; }

.modal{
  position:fixed;
  inset:0;
  z-index:var(--z-modal);
  display:flex;
  align-items:center;
  justify-content:center;
  padding:18px;
}
.modal[hidden],
.modal[aria-hidden="true"],
.modal.hide{
  display:none;
}
.modal--backdrop{
  background:var(--overlay-backdrop);
  backdrop-filter:blur(4px);
  -webkit-backdrop-filter:blur(4px);
}
.modal-backdrop{
  position:absolute;
  inset:0;
  background:var(--overlay-backdrop);
  backdrop-filter:blur(4px);
  -webkit-backdrop-filter:blur(4px);
}
.modal-card,
.modal-dialog,
.sheet{
  position:relative;
  width:min(860px,100%);
  max-height:calc(100vh - 36px);
  overflow:hidden;
  display:flex;
  flex-direction:column;
  border:1px solid var(--stroke);
  border-radius:var(--r);
  background:var(--bg);
  box-shadow:var(--overlay-shadow);
}
.modal-head,
.sheet-header{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:12px;
  padding:14px 16px;
  border-bottom:1px solid var(--stroke);
  background:var(--panel);
}
.modal-head h3,
.modal-head .modal-title{ margin:0; }

.modal-body,
.sheet > .body{
  flex:1 1 auto;
  min-height:0;
  padding:14px 16px;
  overflow:auto;
}
.modal-foot,
.sheet-footer{
  flex:0 0 auto;
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap:10px;
  flex-wrap:wrap;
  padding:12px 16px;
  border-top:1px solid var(--stroke);
  background:var(--panel);
}
body.modal-open{ overflow:hidden; }

/* Variantes de sheets partagées — V3.5. */
.sheet--xl{ max-width:1100px; }
.sheet--mail{
  width:min(620px, calc(100vw - 32px));
  max-height:min(760px, calc(100vh - 48px));
  border-radius:18px;
}
[data-theme="light"] .sheet--paper-light{ background:var(--surface-paper); }
.sheet-header--roomy{ align-items:flex-start; gap:18px; padding:18px 20px; }
.sheet-header--roomy strong{ display:block; margin-bottom:4px; font-size:16px; }
.sheet-body--roomy{ padding:20px; }
.sheet-footer--end{ justify-content:flex-end; }
.sheet-footer--roomy{ padding:14px 20px; }
.modal--strong{ padding:24px; background:var(--overlay-backdrop-strong); }

@media (max-width:768px){
  .modal--bottom-md{ padding:12px; align-items:flex-end; }
  .modal--bottom-md > .sheet{
    width:100%;
    max-height:92vh;
    border-radius:18px 18px 10px 10px;
  }
  .modal--bottom-md .sheet-header--roomy,
  .modal--bottom-md .sheet-body--roomy,
  .modal--bottom-md .sheet-footer--roomy{
    padding-left:16px;
    padding-right:16px;
  }
  .modal--stretch-md{ padding:10px; align-items:stretch; }
  .modal--stretch-md > .sheet{ max-width:none; max-height:calc(100vh - 20px); }
  .modal--stretch-md > .sheet > .sheet-header{
    align-items:flex-start;
    gap:12px;
    flex-direction:column;
  }
  .modal--stretch-md > .sheet > .sheet-header .flex{ width:100%; flex-wrap:wrap; }
}


.hide,
.hidden{ display:none; }

@media (max-width: 560px){
  .grid-2{ grid-template-columns:1fr; }
  .grid-span-2{ grid-column:auto; }
  .modal{ padding:10px; align-items:stretch; }
  .modal-card,
  .modal-dialog,
  .sheet{
    width:100%;
    max-height:calc(100vh - 20px);
  }
  .modal-head,
  .sheet-header{ align-items:flex-start; }
  .modal-foot,
  .sheet-footer{ align-items:stretch; }
  .modal-foot > .left,
  .modal-foot > .right{
    display:flex;
    flex:1 1 100%;
    flex-wrap:wrap;
    gap:8px;
  }
  .modal-foot > .right{ justify-content:flex-end; }
  .modal-foot > .left .btn,
  .modal-foot > .right .btn,
  .sheet-footer > .btn{ flex:1 1 140px; }
}

/* ------------------------------ Utilities --------------------------------- */
.muted{ color: var(--muted); }
.small{ font-size: var(--text-xs); line-height:var(--leading-ui); }
.right{ text-align: right; }

.toast{
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: var(--z-toast);
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border, rgba(255,255,255,.12));
  background: var(--bg);
  color: var(--text, #fff);
  max-width: min(420px, calc(100vw - 32px));
  box-shadow: 0 12px 30px rgba(0,0,0,.35);
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.toast[data-kind="err"],
.toast[data-kind="error"]{
  border-color: rgba(255, 80, 80, .45);
}
.toast[data-kind="ok"],
.toast[data-kind="success"]{
  border-color: rgba(80, 220, 140, .45);
}

/* ------------------------------ Responsive -------------------------------- */
@media (max-width: 1024px){
  .app{ grid-template-columns:1fr; }

  .app-aside{
    position:sticky;
    top:0;
    z-index:var(--z-dropdown);
    height:auto;
    min-width:0;
    padding:10px 16px;
    display:grid;
    grid-template-columns:minmax(0,1fr) auto;
    align-items:center;
    gap:12px;
    overflow:visible;
    border-right:0;
    border-bottom:1px solid var(--stroke);
    background:var(--bg);
    backdrop-filter:none;
  }

  .aside-top{ min-width:0; padding:0; }
  .brand{ min-width:0; }
  .brand-logo{ width:36px; height:36px; border-radius:10px; }
  .brand-sub{ display:none; }

  .mobile-menu-toggle{
    display:inline-flex;
    align-items:center;
    justify-content:center;
    gap:8px;
    min-height:38px;
    padding:7px 10px;
    border:1px solid var(--stroke);
    border-radius:10px;
    background:var(--panel);
    color:var(--text);
    font:inherit;
    font-size:13px;
    font-weight:700;
    cursor:pointer;
  }

  .mobile-menu-toggle__bars{
    display:grid;
    gap:3px;
    width:18px;
  }
  .mobile-menu-toggle__bars > span{
    display:block;
    width:18px;
    height:2px;
    border-radius:999px;
    background:currentColor;
    transition:transform .16s ease, opacity .16s ease;
  }

  .app-aside.is-mobile-menu-open .mobile-menu-toggle__bars > span:nth-child(1){
    transform:translateY(5px) rotate(45deg);
  }
  .app-aside.is-mobile-menu-open .mobile-menu-toggle__bars > span:nth-child(2){
    opacity:0;
  }
  .app-aside.is-mobile-menu-open .mobile-menu-toggle__bars > span:nth-child(3){
    transform:translateY(-5px) rotate(-45deg);
  }

  .aside-menu{
    display:none;
    position:absolute;
    top:100%;
    left:0;
    right:0;
    max-height:calc(100vh - 58px);
    overflow:auto;
    padding:12px 16px 16px;
    border-bottom:1px solid var(--stroke);
    background:var(--bg);
    box-shadow:0 18px 36px rgba(0,0,0,.24);
    backdrop-filter:none;
  }

  .app-aside.is-mobile-menu-open .aside-menu{
    display:flex;
  }

  .nav{
    min-width:0;
    flex-direction:column;
    align-items:stretch;
    gap:4px;
    overflow:visible;
  }

  .nav-item{
    width:100%;
    padding:10px 12px;
    white-space:normal;
  }

  .nav > .btn{
    width:100%;
    min-height:38px;
  }

  .aside-foot{
    display:flex;
    margin-top:4px;
    padding-top:12px;
    border-top:1px solid var(--stroke);
  }
}

@media (max-width: 768px){
  :root{
    --layout-page-x: 16px;
    --layout-page-y: 14px;
  }
  .app-content{ padding-top: 10px; padding-bottom: 28px; }
}

@media (max-width: 560px){
  :root{
    --layout-page-x: 12px;
    --layout-page-y: 12px;
  }
  .header-flex{ align-items: flex-start; flex-wrap: wrap; }

  /* Responsive pratique : actions principales tactiles, actions de tableau compactes. */
  .page-actions > .btn,
  .toolbar > .btn,
  .modal-foot > .btn,
  .modal-foot > .left .btn,
  .modal-foot > .right .btn,
  .sheet-footer > .btn{
    min-height:var(--touch-target-min);
  }
  .nav-item{ min-height:var(--touch-target-min); }
  .table-actions .btn,
  .devis .row-actions .btn,
  .factures-table-card .factures-actions .btn,
  .drafts-table .draft-row-actions .btn,
  .contracts-card .contracts-row-actions .btn,
  .purchases-table-card .purchases-actions .btn{
    min-height:var(--control-h-sm);
    height:var(--control-h-sm);
  }
}

/* Repère d'environnement utile : visible uniquement quand le runtime est sur une BDD *_test. */
.env-badge{
  display:inline-flex;
  align-items:center;
  min-height:26px;
  padding:0 9px;
  border:1px solid var(--stroke);
  border-radius:999px;
  font-size:12px;
  font-weight:700;
  letter-spacing:.08em;
  text-transform:uppercase;
}
.env-badge--test{
  color:var(--warn);
  border-color:color-mix(in srgb,var(--warn) 38%,var(--stroke));
  background:color-mix(in srgb,var(--warn) 9%,transparent);
}
.btn:disabled{
  cursor:not-allowed;
  opacity:.58;
}

.input:disabled,
select:disabled,
textarea:disabled{
  cursor:not-allowed;
  opacity:1;
  color:var(--text-disabled);
  -webkit-text-fill-color:var(--text-disabled);
  background:var(--panel-2);
  border-color:var(--stroke);
}
