/* ==========================================================================
   Factura — feuille de style principale
   Charte Factura : bleu marine institutionnel, un seul bleu d'accent,
   vert réservé à la certification. Surfaces claires, formes sobres.
   ========================================================================== */

:root {
  --c-primary: #1f4e8c;
  --c-primary-dark: #173d6e;
  --c-primary-darker: #0f2744;
  --c-primary-soft: #eef3f9;
  --c-primary-border: #c9d7ea;
  --c-primary-ring: rgba(31, 78, 140, 0.18);
  --c-accent: #1f4e8c;
  --c-accent-soft: #eef3f9;

  --c-bg: #f4f6f9;
  --c-surface: #ffffff;
  --c-surface-2: #f8f9fb;
  --c-text: #111c2d;
  --c-text-2: #344256;
  --c-muted: #64708a;
  --c-border: #e2e6ec;
  --c-border-strong: #cdd3dc;

  --c-success: #15803d;
  --c-success-soft: #edf8f1;
  --c-warning: #b45309;
  --c-warning-soft: #fff7e8;
  --c-danger: #b91c1c;
  --c-danger-soft: #fdf1f1;
  --c-info: #1f4e8c;
  --c-info-soft: #eef3f9;
  --c-credit: #4c3d99;
  --c-credit-soft: #f3f1fb;
  --c-credit-border: #dcd6f2;

  --sidebar-bg: #0f2744;
  --sidebar-text: #aebbd0;
  --sidebar-text-strong: #ffffff;
  --sidebar-active: rgba(255, 255, 255, 0.09);
  --sidebar-highlight: #8fb4e3;
  --sidebar-w: 256px;

  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 2px rgba(17, 28, 45, 0.05);
  --shadow-md: 0 4px 12px rgba(17, 28, 45, 0.08);
  --shadow-lg: 0 16px 36px rgba(17, 28, 45, 0.16);
  --font: "Segoe UI Variable Text", "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --font-num: "Segoe UI Variable Display", "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--c-bg);
  color: var(--c-text);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--c-primary); text-decoration: none; }
a:hover { color: var(--c-primary-dark); text-decoration: underline; }

code {
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 0.85em;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: 5px;
  padding: 1px 6px;
}

:focus-visible { outline: 2px solid var(--c-primary); outline-offset: 2px; }

.container { width: 100%; }

/* ==========================================================================
   Coquille applicative : barre latérale + zone principale
   ========================================================================== */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  z-index: 60;
  transition: transform 0.25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 20px 18px;
  color: #fff;
  text-decoration: none;
}
.sidebar-brand:hover { color: #fff; text-decoration: none; }

.brand-logo {
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  flex-shrink: 0;
  color: var(--c-primary);
}
.brand-logo-img { width: 100%; height: 100%; object-fit: contain; padding: 3px; }

.brand-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand-name { font-weight: 700; font-size: 1.08rem; letter-spacing: 0.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-sub { white-space: nowrap; font-size: 0.72rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--sidebar-highlight); font-weight: 600; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: 6px 12px 12px; }

.nav-section {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: #6c7f9c;
  padding: 18px 12px 6px;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  margin: 2px 0;
  border-radius: 6px;
  color: var(--sidebar-text);
  font-size: 0.93rem;
  font-weight: 500;
  position: relative;
  transition: background 0.15s, color 0.15s;
}
.nav-link svg { flex-shrink: 0; opacity: 0.85; }
.nav-link:hover { background: rgba(255, 255, 255, 0.06); color: #fff; text-decoration: none; }
.nav-link.active {
  background: var(--sidebar-active);
  color: var(--sidebar-text-strong);
  font-weight: 600;
}
.nav-link.active svg { color: var(--sidebar-highlight); opacity: 1; }
.nav-link.active::before {
  content: "";
  position: absolute;
  left: -12px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  border-radius: 0 2px 2px 0;
  background: var(--sidebar-highlight);
}

.sidebar-cta {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin: 4px 12px 0;
  padding: 10px 14px;
  border-radius: 6px;
  background: #2f64a8;
  color: #fff;
  font-weight: 600;
  font-size: 0.92rem;
}
.sidebar-cta:hover { color: #fff; text-decoration: none; background: #3a72ba; }

.sidebar-footer {
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #2f64a8;
  color: #fff;
  font-weight: 700;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  flex-shrink: 0;
}

.user-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; flex: 1; }
.user-name { color: #fff; font-weight: 600; font-size: 0.9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-role { font-size: 0.75rem; color: #8193ad; }

.logout-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 6px;
  color: var(--sidebar-text);
  transition: background 0.15s, color 0.15s;
}
.logout-btn:hover { background: rgba(255, 255, 255, 0.08); color: #fff; }

.shell-main {
  flex: 1;
  min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ---------- Barre supérieure ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: var(--c-surface);
  border-bottom: 1px solid var(--c-border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 64px;
  padding: 0 32px;
}

.menu-toggle {
  display: none;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 6px;
  border: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-text);
  cursor: pointer;
}

.topbar-title { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.topbar-crumb { font-size: 0.75rem; color: var(--c-muted); }
.topbar-page { font-weight: 650; font-size: 1rem; color: var(--c-text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.topbar-spacer { flex: 1; }

.topbar-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border-radius: 6px;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  color: var(--c-text-2);
  font-size: 0.83rem;
  white-space: nowrap;
}
.topbar-chip .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--c-success); }
.topbar-company { font-weight: 600; color: var(--c-text); max-width: 280px; }
.topbar-company img { width: 20px; height: 20px; object-fit: contain; border-radius: 3px; flex-shrink: 0; }
.topbar-company span { overflow: hidden; text-overflow: ellipsis; }

.sidebar-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(10, 22, 40, 0.45);
  z-index: 55;
}

/* ---------- Contenu ---------- */
main { flex: 1; }
.content { padding: 28px 32px 40px; width: 100%; max-width: 1320px; }

.footer strong { color: var(--c-text-2); font-weight: 600; }
.footer {
  border-top: 1px solid var(--c-border);
  background: var(--c-surface);
  color: var(--c-muted);
  font-size: 0.8rem;
  padding: 16px 32px;
  display: flex;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.nav-open .sidebar { transform: none; }
  body.nav-open .sidebar-backdrop { display: block; }
  .shell-main { margin-left: 0; }
  .menu-toggle { display: inline-flex; }
}

@media (max-width: 640px) {
  .topbar-inner { padding: 0 16px; }
  .content { padding: 20px 16px 32px; }
  .footer { padding: 14px 16px; }
  .topbar-chip.hide-sm { display: none; }
}

/* ==========================================================================
   En-tête de page
   ========================================================================== */
.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
  margin-bottom: 24px;
}

.page-header h1 {
  margin: 0;
  font-size: 1.6rem;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--c-text);
}

.page-header .lead { color: var(--c-muted); margin: 4px 0 0; font-size: 0.95rem; }

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-primary);
  margin-bottom: 4px;
}

/* ==========================================================================
   Cartes & grilles
   ========================================================================== */
.card {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

.card + .card { margin-top: 20px; }
.grid > .card + .card { margin-top: 0; }

.card-title {
  margin: 0 0 16px;
  font-size: 1.02rem;
  font-weight: 650;
  color: var(--c-text);
  display: flex;
  align-items: center;
  gap: 10px;
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
}
.card-head .card-title { margin: 0; }

.title-icon {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  flex-shrink: 0;
}

.grid { display: grid; gap: 20px; grid-template-columns: minmax(0, 1fr); }
.grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid-main { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

@media (max-width: 1100px) {
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid-main { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 900px) {
  .grid-3, .grid-2 { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 520px) {
  .grid-4 { grid-template-columns: minmax(0, 1fr); }
}

/* ==========================================================================
   Indicateurs (KPI)
   ========================================================================== */
.kpi {
  background: var(--c-surface);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 2px;
  position: relative;
  overflow: hidden;
  transition: box-shadow 0.2s, transform 0.2s;
}
.kpi { border-top: 3px solid var(--c-primary); }
.kpi.alt-1 { border-top-color: var(--c-success); }
.kpi.alt-2 { border-top-color: #d97706; }
.kpi.alt-3 { border-top-color: var(--c-primary-darker); }

.kpi-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 8px; }

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: 7px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--c-primary-soft);
  color: var(--c-primary);
}

.kpi .kpi-label { color: var(--c-muted); font-size: 0.82rem; font-weight: 600; }
.kpi .kpi-value { font-family: var(--font-num); font-size: 1.65rem; font-weight: 700; letter-spacing: -0.01em; color: var(--c-text); font-variant-numeric: tabular-nums; }
.kpi .kpi-value .unit { font-size: 0.9rem; font-weight: 600; color: var(--c-muted); margin-left: 4px; }
.kpi .kpi-sub { color: var(--c-muted); font-size: 0.8rem; }

.kpi.alt-1 .kpi-icon { background: var(--c-success-soft); color: var(--c-success); }
.kpi.alt-2 .kpi-icon { background: var(--c-warning-soft); color: var(--c-warning); }
.kpi.alt-3 .kpi-icon { background: #e9edf3; color: var(--c-primary-darker); }

/* Bannière d'accueil */
.welcome {
  position: relative;
  overflow: hidden;
  border-radius: var(--radius);
  padding: 26px 28px;
  margin-bottom: 24px;
  color: #fff;
  background: var(--sidebar-bg);
  border-left: 4px solid var(--sidebar-highlight);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}
.welcome h1 { margin: 0; font-size: 1.55rem; font-weight: 700; color: #fff; }
.welcome p { margin: 6px 0 0; opacity: 0.88; }
.welcome .eyebrow { color: var(--sidebar-highlight); }
.welcome-actions { display: flex; gap: 10px; flex-wrap: wrap; position: relative; z-index: 1; }
.welcome .btn-light { background: #fff; color: var(--c-primary-darker); }
.welcome .btn-light:hover { background: #eef3f9; color: var(--c-primary-darker); }
.welcome .btn-ghost { background: rgba(255, 255, 255, 0.14); border-color: rgba(255, 255, 255, 0.3); color: #fff; }
.welcome .btn-ghost:hover { background: rgba(255, 255, 255, 0.22); color: #fff; }

/* Période des indicateurs */
.period-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 14px; }
.period-nav { display: flex; align-items: center; gap: 8px; }
.period-label { font-weight: 650; color: var(--c-text); min-width: 130px; text-align: center; }

/* Accès rapides */
.quick-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.quick {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 7px;
  border: 1px solid var(--c-border);
  background: var(--c-surface-2);
  color: var(--c-text);
  font-weight: 600;
  font-size: 0.9rem;
  transition: border-color 0.15s, background 0.15s, transform 0.15s;
}
.quick:hover { border-color: var(--c-primary); background: var(--c-primary-soft); color: var(--c-primary-darker); text-decoration: none; }
.quick .title-icon { width: 34px; height: 34px; }
.quick small { display: block; font-weight: 400; color: var(--c-muted); font-size: 0.76rem; }

/* Répartition des statuts : barres horizontales (une seule série) */
.status-bars { display: flex; flex-direction: column; gap: 12px; }
.status-bar-row { display: grid; grid-template-columns: 120px 1fr 36px; align-items: center; gap: 10px; font-size: 0.86rem; }
.status-bar-track { height: 8px; background: var(--c-surface-2); border-radius: 4px; overflow: hidden; }
.status-bar-fill { height: 100%; border-radius: 4px; background: var(--c-primary); min-width: 4px; }
.status-bar-row .num { text-align: right; font-weight: 600; font-variant-numeric: tabular-nums; color: var(--c-text-2); }

/* ==========================================================================
   Alertes
   ========================================================================== */
.alert {
  position: relative;
  border-radius: var(--radius-sm);
  padding: 12px 16px 12px 44px;
  margin-bottom: 18px;
  font-size: 0.92rem;
  border: 1px solid transparent;
  border-left-width: 4px;
}
.alert::before {
  content: "";
  position: absolute;
  left: 16px;
  top: 13px;
  width: 18px;
  height: 18px;
  background: currentColor;
  -webkit-mask: var(--alert-icon) center / contain no-repeat;
  mask: var(--alert-icon) center / contain no-repeat;
}

.alert-success {
  background: var(--c-success-soft); border-color: #bbf0cf; border-left-color: var(--c-success); color: #14532d;
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='m8 12 3 3 5-6'/%3E%3C/svg%3E");
}
.alert-error, .alert-danger {
  background: var(--c-danger-soft); border-color: #fbcaca; border-left-color: var(--c-danger); color: #7f1d1d;
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M15 9l-6 6M9 9l6 6'/%3E%3C/svg%3E");
}
.alert-warning {
  background: var(--c-warning-soft); border-color: #fde3a7; border-left-color: #d97706; color: #78350f;
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M10.3 3.9 1.8 18a2 2 0 0 0 1.7 3h17a2 2 0 0 0 1.7-3L13.7 3.9a2 2 0 0 0-3.4 0z'/%3E%3Cpath d='M12 9v4M12 17h.01'/%3E%3C/svg%3E");
}
.alert-info {
  background: var(--c-info-soft); border-color: #c4e3f6; border-left-color: var(--c-info); color: #0c4a6e;
  --alert-icon: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'%3E%3Ccircle cx='12' cy='12' r='10'/%3E%3Cpath d='M12 16v-4M12 8h.01'/%3E%3C/svg%3E");
}

/* ==========================================================================
   Boutons
   ========================================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: var(--c-primary);
  color: #fff;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  box-shadow: none;
  transition: background 0.15s, box-shadow 0.15s, transform 0.05s, border-color 0.15s;
}
.btn:hover { background: var(--c-primary-dark); color: #fff; text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-secondary { background: var(--c-surface); color: var(--c-text-2); border-color: var(--c-border-strong); box-shadow: none; }
.btn-secondary:hover { background: var(--c-surface-2); color: var(--c-text); border-color: #b7c4d0; box-shadow: none; }

.btn-danger { background: var(--c-danger); }
.btn-danger:hover { background: #991b1b; }

.btn-success { background: var(--c-success); }
.btn-success:hover { background: #166534; }

.btn-warning { background: #d97706; }
.btn-warning:hover { background: var(--c-warning); }

.btn-sm, .btn-small { padding: 6px 12px; font-size: 0.83rem; }
.btn-block { width: 100%; }
.btn-lg { padding: 12px 20px; font-size: 0.98rem; }

.btn[disabled], .btn.disabled { opacity: 0.5; pointer-events: none; }

/* ==========================================================================
   Formulaires
   ========================================================================== */
.field { margin-bottom: 16px; }

.field label {
  display: block;
  margin-bottom: 6px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--c-text-2);
}

.field .hint, .hint { font-size: 0.8rem; color: var(--c-muted); margin-top: 4px; font-weight: 400; }

.input, select.input, textarea.input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--c-border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.93rem;
  font-family: inherit;
  color: var(--c-text);
  background: var(--c-surface);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input::placeholder { color: #9aa8b6; }
.input:hover { border-color: #b7c4d0; }
.input:focus {
  outline: none;
  border-color: var(--c-primary);
  box-shadow: 0 0 0 3px var(--c-primary-ring);
}
.input[readonly] { background: var(--c-surface-2); color: var(--c-text-2); cursor: default; }
.input[readonly]:focus { box-shadow: none; border-color: var(--c-border-strong); }

select.input {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
}

input[type="file"].input { padding: 7px; }
input[type="file"].input::file-selector-button {
  border: 1px solid var(--c-border-strong);
  background: var(--c-surface-2);
  border-radius: 7px;
  padding: 5px 10px;
  margin-right: 10px;
  font-family: inherit;
  cursor: pointer;
}

textarea.input { min-height: 84px; resize: vertical; }

.form-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; }

.form-actions {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 20px;
  flex-wrap: wrap;
}

.form-section {
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--c-muted);
  margin: 22px 0 12px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--c-border);
}
.form-section:first-child { margin-top: 0; }

.required::after { content: " *"; color: var(--c-danger); }
.text-error { color: var(--c-danger); }

/* Barre de filtres */
.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  padding-bottom: 16px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--c-border);
}

.search-input { position: relative; flex: 1 1 240px; max-width: 360px; }
.search-input svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--c-muted); pointer-events: none; }
.search-input .input { padding-left: 38px; }

/* ==========================================================================
   Tableaux
   ========================================================================== */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }

table.table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 0.9rem;
}

.table th {
  text-align: left;
  padding: 11px 14px;
  background: var(--c-surface-2);
  color: var(--c-muted);
  font-weight: 650;
  font-size: 0.74rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--c-border);
  white-space: nowrap;
}
.table th:first-child { border-top-left-radius: 9px; }
.table th:last-child { border-top-right-radius: 9px; }

.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--c-border);
  vertical-align: middle;
  color: var(--c-text-2);
}
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background 0.12s; }
.table tbody tr:hover { background: #f6f8fb; }
.table td strong { color: var(--c-text); }
.table td a strong, .table td > a { font-weight: 600; }

.table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }

.table td.empty {
  text-align: center;
  padding: 40px 14px;
  color: var(--c-muted);
}
.empty-icon {
  display: inline-flex;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  margin-bottom: 8px;
}

.cell-main { display: flex; align-items: center; gap: 10px; }
.cell-avatar {
  width: 32px;
  height: 32px;
  border-radius: 6px;
  background: var(--c-primary-soft);
  color: var(--c-primary);
  font-weight: 700;
  font-size: 0.8rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-transform: uppercase;
  flex-shrink: 0;
}

/* ==========================================================================
   Badges
   ========================================================================== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 9px;
  border-radius: 4px;
  font-size: 0.76rem;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; }

.badge-draft { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }
.badge-validated { background: var(--c-info-soft); color: var(--c-info); border-color: var(--c-primary-border); }
.badge-sending { background: var(--c-warning-soft); color: var(--c-warning); border-color: #fde3a7; }
.badge-certified { background: var(--c-success-soft); color: var(--c-success); border-color: #c4ecd3; }
.badge-paid { background: #e9edf3; color: var(--c-primary-darker); border-color: #cdd5e1; }
.badge-failed { background: var(--c-danger-soft); color: var(--c-danger); border-color: #fbcaca; }
.badge-cancelled { background: #f1f5f9; color: #8492a6; border-color: #e2e8f0; }
.badge-converted { background: var(--c-info-soft); color: var(--c-info); border-color: var(--c-primary-border); }
.badge-credit { background: var(--c-credit-soft); color: var(--c-credit); border-color: var(--c-credit-border); }
.badge-ok { background: var(--c-success-soft); color: var(--c-success); border-color: #c4ecd3; }
.badge-off { background: #f1f5f9; color: #64748b; border-color: #e2e8f0; }

/* ==========================================================================
   Onglets (formulaire facture)
   ========================================================================== */
.tabs {
  display: flex;
  gap: 4px;
  margin: 0 -24px 24px;
  padding: 0 16px;
  border-bottom: 1px solid var(--c-border);
  flex-wrap: wrap;
  counter-reset: step;
}

.tab {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 16px 14px 14px;
  background: transparent;
  border: none;
  border-bottom: 3px solid transparent;
  margin-bottom: -1px;
  cursor: pointer;
  font-family: inherit;
  font-size: 0.92rem;
  font-weight: 600;
  color: var(--c-muted);
  transition: color 0.15s, border-color 0.15s;
  text-decoration: none;
}
.tab:hover { color: var(--c-primary); }

.tab-icon {
  display: inline-flex;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  align-items: center;
  justify-content: center;
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.tab.active { color: var(--c-primary-darker); border-bottom-color: var(--c-primary); }
.tab.active .tab-icon { background: var(--c-primary); color: #fff; border-color: var(--c-primary); box-shadow: 0 4px 10px rgba(31, 78, 140, 0.28); }

.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 0.22s ease; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* ==========================================================================
   Lignes de facture
   ========================================================================== */
.items-table-wrap { overflow-x: auto; border: 1px solid var(--c-border); border-radius: 8px; }

.items-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }

.items-table th {
  background: var(--c-surface-2);
  color: var(--c-muted);
  padding: 10px 8px;
  text-align: left;
  font-size: 0.72rem;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
  border-bottom: 1px solid var(--c-border);
}

.items-table td { padding: 8px 6px; border-bottom: 1px solid var(--c-border); vertical-align: middle; }
.items-table tbody tr:last-child td { border-bottom: none; }
.items-table tbody tr:hover { background: #f7fbfd; }
.items-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.items-table input, .items-table select {
  width: 100%;
  padding: 7px 8px;
  border: 1px solid var(--c-border-strong);
  border-radius: 7px;
  font-size: 0.88rem;
  font-family: inherit;
  background: var(--c-surface);
  color: var(--c-text);
}
.items-table input:focus, .items-table select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-ring); }

.items-table .col-des { min-width: 220px; }
.items-table .col-small { width: 90px; }
.items-table .col-tax { width: 120px; }
.items-table .line-total { font-weight: 700; color: var(--c-text); }
.items-table .btn-del {
  background: transparent;
  border: none;
  color: var(--c-muted);
  cursor: pointer;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.items-table .btn-del:hover { background: var(--c-danger-soft); color: var(--c-danger); }

.add-line-btn {
  margin-top: 14px;
  border: 1.5px dashed #9cc9e0;
  color: var(--c-primary);
  background: var(--c-primary-soft);
  padding: 11px 16px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: background 0.15s, border-color 0.15s;
}
.add-line-btn:hover { background: #d9eef8; border-color: var(--c-primary); }

/* ==========================================================================
   Totaux
   ========================================================================== */
.totals-panel {
  background: var(--c-surface-2);
  border: 1px solid var(--c-border);
  border-radius: var(--radius);
  padding: 18px 20px;
}
.totals-panel .total-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; font-size: 0.92rem; color: var(--c-text-2); font-variant-numeric: tabular-nums; }
.totals-panel .total-row + .total-row { border-top: 1px dashed var(--c-border); }
.totals-panel .total-row.grand { font-size: 1.15rem; font-weight: 800; color: var(--c-primary-darker); border-top: 2px solid var(--c-border-strong); margin-top: 6px; padding-top: 12px; }
.totals-panel .total-row.due {
  font-size: 1.08rem;
  font-weight: 700;
  color: #fff;
  background: var(--c-primary-darker);
  border-radius: 6px;
  padding: 12px 14px;
  margin-top: 10px;
  border-top: none;
}
.totals-panel #add-tax-btn { margin-top: 12px; }

/* ==========================================================================
   Document facture (écran + impression)
   ========================================================================== */
.invoice-doc-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
  border-top: 5px solid var(--c-primary);
  margin-bottom: 20px;
}

.invoice-doc-brand { display: flex; align-items: center; gap: 16px; }
.invoice-doc-logo { height: 72px; max-width: 180px; width: auto; object-fit: contain; }
.invoice-doc-identity { display: flex; flex-direction: column; gap: 2px; }
.invoice-doc-name { font-size: 1.2rem; font-weight: 800; color: var(--c-primary-darker); line-height: 1.2; }
.invoice-doc-activity { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.02em; color: var(--c-muted); text-transform: uppercase; line-height: 1.35; }
.invoice-doc-contact { font-size: 0.82rem; color: var(--c-muted); margin-top: 4px; }

.invoice-doc-title { text-align: right; }
.invoice-doc-title-label { font-size: 1.55rem; font-weight: 800; color: var(--c-text); letter-spacing: 0.06em; }
.invoice-doc-title-number { font-size: 0.95rem; color: var(--c-muted); font-weight: 600; margin-top: 2px; }

.invoice-doc-legal {
  border-top: 1px solid var(--c-border);
  margin-top: 24px;
  padding-top: 12px;
  font-size: 0.78rem;
  color: var(--c-muted);
  text-align: center;
}

.invoice-meta { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 20px; }
.meta-item { background: var(--c-surface-2); border: 1px solid var(--c-border); border-radius: 6px; padding: 10px 14px; }
.meta-item .meta-label { font-size: 0.7rem; color: var(--c-muted); text-transform: uppercase; letter-spacing: 0.06em; font-weight: 600; }
.meta-item .meta-value { font-weight: 650; margin-top: 2px; color: var(--c-text); overflow-wrap: anywhere; }

.action-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.action-bar form { margin: 0; }

/* ==========================================================================
   Bouton icône
   ========================================================================== */
.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--c-border);
  border-radius: 6px;
  background: var(--c-surface);
  color: var(--c-text-2);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.icon-btn:hover { background: var(--c-primary-soft); color: var(--c-primary); border-color: var(--c-primary-border); text-decoration: none; }
.icon-btn.danger:hover { background: var(--c-danger-soft); color: var(--c-danger); }

/* ==========================================================================
   Étapes de statut
   ========================================================================== */
.status-flow { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 10px 0 4px; }
.status-step { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; color: var(--c-muted); padding: 4px 10px; border-radius: 4px; background: #f1f3f6; }
.status-step.done { background: var(--c-success-soft); color: var(--c-success); font-weight: 600; }
.status-step.current { background: var(--c-primary); color: #fff; font-weight: 700; }
.status-arrow { color: var(--c-border-strong); font-weight: 700; }

/* ==========================================================================
   Authentification (connexion / configuration initiale)
   ========================================================================== */
body.auth-body { background: var(--c-surface); }

.auth-shell { display: grid; grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr); min-height: 100vh; }

.auth-hero {
  position: relative;
  overflow: hidden;
  color: #fff;
  padding: 48px 56px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background-color: var(--sidebar-bg);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px);
  background-size: 40px 40px;
}
.auth-hero-brand { display: flex; align-items: center; gap: 14px; position: relative; z-index: 1; }
.auth-hero-brand .brand-logo { width: 46px; height: 46px; border-radius: 6px; }
.auth-hero-brand .brand-name { font-size: 1.3rem; }
.auth-hero-brand .brand-sub { color: var(--sidebar-highlight); }
.auth-hero-copy { position: relative; z-index: 1; max-width: 460px; }
.auth-hero-copy h2 { font-size: 2.1rem; line-height: 1.15; margin: 0 0 14px; font-weight: 700; letter-spacing: -0.015em; }
.auth-hero-copy p { margin: 0; opacity: 0.85; font-size: 1rem; }
.auth-features { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; }
.auth-features li { display: flex; align-items: center; gap: 12px; font-size: 0.93rem; opacity: 0.95; }
.auth-features .f-icon { width: 32px; height: 32px; border-radius: 6px; background: rgba(255, 255, 255, 0.08); border: 1px solid rgba(255, 255, 255, 0.12); display: inline-flex; align-items: center; justify-content: center; color: var(--sidebar-highlight); flex-shrink: 0; }
.auth-hero-foot { position: relative; z-index: 1; font-size: 0.8rem; opacity: 0.65; }

.auth-panel { display: flex; align-items: center; justify-content: center; padding: 40px 24px; background: var(--c-bg); }
.auth-wrap { width: 100%; max-width: 420px; }
.auth-card { padding: 36px 32px; border-radius: 6px; box-shadow: var(--shadow-md); }
.auth-company { display: flex; align-items: center; gap: 12px; padding: 0 0 18px; margin: 0 0 22px; border-bottom: 1px solid var(--c-border); }
.auth-company img { width: 44px; height: 44px; object-fit: contain; border: 1px solid var(--c-border); border-radius: 6px; padding: 4px; background: #fff; flex-shrink: 0; }
.auth-company-label { display: block; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--c-muted); font-weight: 600; }
.auth-company-name { display: block; font-weight: 700; color: var(--c-text); }
.auth-card h1 { margin: 0 0 6px; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }
.auth-card .auth-lead { color: var(--c-muted); margin: 0 0 24px; font-size: 0.93rem; }

.auth-logo {
  width: 56px;
  height: 56px;
  margin: 0 0 18px;
  border-radius: 6px;
  background: var(--c-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  overflow: hidden;
}
.auth-logo.has-img { width: 72px; height: 72px; background: #fff; border: 1px solid var(--c-border); }
.auth-logo img { width: 100%; height: 100%; object-fit: contain; padding: 6px; }

.input-icon { position: relative; }
.input-icon svg { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--c-muted); pointer-events: none; }
.input-icon .input { padding-left: 40px; }

.auth-secure { display: flex; align-items: center; justify-content: center; gap: 6px; margin-top: 18px; font-size: 0.78rem; color: var(--c-muted); }

@media (max-width: 900px) {
  .auth-shell { grid-template-columns: minmax(0, 1fr); }
  .auth-hero { padding: 28px 24px; min-height: auto; }
  .auth-hero-copy h2 { font-size: 1.5rem; }
  .auth-features, .auth-hero-foot { display: none; }
  .auth-hero-copy { margin-top: 18px; }
}

/* Page d'erreur */
.error-state { text-align: center; padding: 56px 24px; max-width: 560px; margin: 40px auto; }
.error-state .empty-icon { width: 72px; height: 72px; background: var(--c-danger-soft); color: var(--c-danger); margin-bottom: 14px; }
.error-state h1 { margin: 0 0 8px; font-size: 1.45rem; }
.error-state p { color: var(--c-muted); margin: 0 0 22px; }

/* ==========================================================================
   Divers
   ========================================================================== */
.qr-box { text-align: center; }
.qr-box img { max-width: 160px; border: 1px solid var(--c-border); border-radius: 8px; padding: 8px; background: #fff; }

.logo-drop {
  display: flex;
  align-items: center;
  gap: 18px;
  flex-wrap: wrap;
  padding: 16px;
  border: 1.5px dashed var(--c-border-strong);
  border-radius: 8px;
  background: var(--c-surface-2);
  margin-bottom: 20px;
}
.logo-preview {
  width: 140px;
  height: 84px;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--c-border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--c-muted);
  font-size: 0.85rem;
  overflow: hidden;
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; padding: 6px; }

.security-state {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: 8px;
  border: 1px solid var(--c-border);
  background: var(--c-surface-2);
  margin-bottom: 14px;
}

details > summary { list-style: none; }
details > summary::-webkit-details-marker { display: none; }

.muted { color: var(--c-muted); }
.small { font-size: 0.85rem; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.mt-3 { margin-top: 24px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.flex { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }

/* ==========================================================================
   Composeur de facture
   ========================================================================== */
[hidden] { display: none !important; }

.composer { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 24px; align-items: start; }
.composer-main { display: flex; flex-direction: column; gap: 20px; min-width: 0; }
.composer-main .card + .card { margin-top: 0; }
.composer-main > .alert { margin-bottom: 0; }
.composer-side { position: sticky; top: 88px; }

.step-head { display: flex; align-items: flex-start; gap: 14px; margin-bottom: 18px; }
.step-head > div { flex: 1; min-width: 0; }
.step-title { margin: 0; font-size: 1.05rem; font-weight: 650; display: flex; align-items: center; flex-wrap: wrap; }
.step-sub { margin: 2px 0 0; color: var(--c-muted); font-size: 0.86rem; }
.step-action { flex-shrink: 0; }
.step-num {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; position: relative;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 0.9rem;
  background: var(--c-primary-soft); color: var(--c-primary);
  border: 1px solid #c7e3f1;
  transition: background 0.2s, color 0.2s;
}
.step.done .step-num { background: var(--c-success); border-color: var(--c-success); color: transparent; }
.step.done .step-num::after {
  content: ""; position: absolute; inset: 0; background: #fff;
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12 4 4 8-8'/%3E%3C/svg%3E") center / 16px no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='3' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m6 12 4 4 8-8'/%3E%3C/svg%3E") center / 16px no-repeat;
}

/* Cartes de choix (type de document) */
.choice-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.choice { position: relative; cursor: pointer; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-body {
  display: flex; flex-direction: column; gap: 4px; height: 100%;
  padding: 14px 16px; border-radius: 8px;
  border: 1.5px solid var(--c-border-strong); background: var(--c-surface);
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
}
.choice:hover .choice-body { border-color: #9cc9e0; }
.choice input:checked + .choice-body { border-color: var(--c-primary); background: var(--c-primary-soft); box-shadow: 0 0 0 3px var(--c-primary-ring); }
.choice input:focus-visible + .choice-body { outline: 2px solid var(--c-primary); outline-offset: 2px; }
.choice input:disabled + .choice-body { cursor: not-allowed; opacity: 0.55; }
.choice input:disabled:checked + .choice-body { opacity: 1; }
.choice-icon { width: 36px; height: 36px; border-radius: 6px; display: inline-flex; align-items: center; justify-content: center; background: var(--c-surface-2); color: var(--c-muted); margin-bottom: 4px; }
.choice input:checked + .choice-body .choice-icon { background: var(--c-primary); color: #fff; }
.choice-title { font-weight: 650; color: var(--c-text); font-size: 0.93rem; }
.choice-desc { font-size: 0.8rem; color: var(--c-muted); line-height: 1.35; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--c-border-strong); background: var(--c-surface); color: var(--c-text-2);
  border-radius: 999px; padding: 3px 11px; font-size: 0.78rem; font-family: inherit; cursor: pointer;
}
.chip:hover { border-color: var(--c-primary); color: var(--c-primary); background: var(--c-primary-soft); }

/* Liste déroulante de recherche */
.combo { position: relative; }
.combo-list {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30;
  background: var(--c-surface); border: 1px solid var(--c-border); border-radius: 8px;
  box-shadow: var(--shadow-lg); max-height: 340px; overflow-y: auto; padding: 6px;
}
.combo-item { display: flex; align-items: center; gap: 12px; padding: 9px 10px; border-radius: 6px; cursor: pointer; }
.combo-item.active, .combo-item:hover { background: var(--c-primary-soft); }
.combo-main { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.combo-main strong, .combo-side strong { font-weight: 600; color: var(--c-text); font-size: 0.92rem; }
.combo-main strong { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.combo-main small, .combo-side small { color: var(--c-muted); font-size: 0.77rem; }
.combo-side { display: flex; flex-direction: column; align-items: flex-end; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.combo-empty { padding: 14px; color: var(--c-muted); font-size: 0.88rem; text-align: center; }

.search-lg .input { padding-top: 12px; padding-bottom: 12px; font-size: 0.97rem; padding-right: 80px; }
.search-input .kbd { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); }
.kbd {
  display: inline-block; font-family: inherit; font-size: 0.72rem; font-weight: 600; color: var(--c-muted);
  background: var(--c-surface-2); border: 1px solid var(--c-border-strong); border-bottom-width: 2px;
  border-radius: 5px; padding: 1px 6px; line-height: 1.4;
}

/* Client sélectionné */
.selected-client {
  display: flex; align-items: center; gap: 14px;
  padding: 14px 16px; border-radius: 8px;
  background: var(--c-primary-soft);
  border: 1px solid #cfe7ef;
}
.avatar-lg { width: 44px; height: 44px; font-size: 1.1rem; }
.selected-info { flex: 1; min-width: 0; }
.selected-info > strong { font-size: 1rem; color: var(--c-text); }
.selected-meta { display: flex; flex-wrap: wrap; gap: 6px 12px; align-items: center; margin-top: 4px; font-size: 0.82rem; color: var(--c-text-2); }

/* Lignes (une carte par article) */
.lines-wrap { margin-top: 16px; border: 1px solid var(--c-border); border-radius: 8px; overflow: hidden; }
.lines-list.is-empty { display: none; }
.item-row { padding: 14px 16px; transition: background 0.2s; }
.item-row + .item-row { border-top: 1px solid var(--c-border); }
.item-row:hover { background: #fafcfd; }

.line-main {
  display: grid;
  grid-template-columns: 124px 190px 116px minmax(0, 1fr) auto;
  grid-template-areas:
    "des des des des act"
    "qty price tax total total";
  gap: 10px 14px;
  align-items: end;
}
.l-des { grid-area: des; min-width: 0; }
.l-act { grid-area: act; justify-self: end; align-self: start; display: flex; gap: 4px; }
.l-qty { grid-area: qty; }
.l-price { grid-area: price; }
.l-tax { grid-area: tax; }
.l-total { grid-area: total; text-align: right; }
.l-lbl { display: block; font-size: 0.7rem; font-weight: 650; letter-spacing: 0.05em; text-transform: uppercase; color: var(--c-muted); margin-bottom: 4px; }

.item-row input, .item-row select {
  width: 100%; padding: 8px 9px; border: 1px solid var(--c-border-strong); border-radius: 8px;
  font-size: 0.9rem; font-family: inherit; background: var(--c-surface); color: var(--c-text);
}
.item-row select { appearance: auto; }
.item-row input:focus, .item-row select:focus { outline: none; border-color: var(--c-primary); box-shadow: 0 0 0 3px var(--c-primary-ring); }
.item-row .line-designation { font-weight: 600; font-size: 0.95rem; padding: 9px 11px; }
.line-meta { font-size: 0.76rem; color: var(--c-muted); margin-top: 5px; }
.line-meta:empty { display: none; }
.l-act .icon-btn { width: 34px; height: 34px; }
.icon-btn.on { background: var(--c-primary-soft); color: var(--c-primary); border-color: var(--c-primary-border); }
.line-total { display: block; font-size: 1.05rem; font-weight: 750; color: var(--c-text); font-variant-numeric: tabular-nums; padding-bottom: 7px; }

.stepper { display: flex; align-items: stretch; border: 1px solid var(--c-border-strong); border-radius: 8px; overflow: hidden; background: var(--c-surface); }
.stepper button { width: 34px; flex-shrink: 0; border: 0; background: var(--c-surface-2); color: var(--c-text-2); font-size: 1.05rem; cursor: pointer; font-family: inherit; }
.stepper button:hover { background: var(--c-primary-soft); color: var(--c-primary); }
.item-row .stepper input { border: 0; border-radius: 0; text-align: center; padding: 8px 2px; min-width: 0; box-shadow: none; }

.price-group { display: flex; }
.item-row .price-group input { border-top-right-radius: 0; border-bottom-right-radius: 0; text-align: right; min-width: 0; }
.item-row .price-group select { width: 66px; flex-shrink: 0; border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; background-color: var(--c-surface-2); padding: 8px 4px; }

.line-details { margin-top: 12px; }
.details-grid {
  display: grid; grid-template-columns: 140px minmax(0, 1fr) 190px auto; gap: 12px; align-items: end;
  padding: 12px; border-radius: 6px; background: var(--c-surface-2); border: 1px dashed var(--c-border-strong);
}
.details-grid label { display: flex; flex-direction: column; gap: 4px; font-size: 0.75rem; font-weight: 600; color: var(--c-muted); }
.details-figures { display: flex; gap: 16px; font-size: 0.8rem; color: var(--c-muted); padding-bottom: 8px; white-space: nowrap; }
.details-figures strong { color: var(--c-text); font-variant-numeric: tabular-nums; }

.lines-empty { text-align: center; padding: 34px 16px; color: var(--c-text-2); }

@keyframes rowFlash { from { background: #d7f3ee; } to { background: transparent; } }
.item-row.flash-row { animation: rowFlash 1.1s ease; }

.input.invalid, .item-row input.invalid { border-color: var(--c-danger) !important; box-shadow: 0 0 0 3px rgba(200, 30, 30, 0.15) !important; }

@media (max-width: 760px) {
  .line-main {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    grid-template-areas:
      "des des"
      "qty price"
      "tax total"
      "act act";
  }
  .l-act { justify-self: start; }
  .details-grid { grid-template-columns: minmax(0, 1fr); }
}

/* Paiement */
.pay-grid { display: flex; flex-wrap: wrap; gap: 8px; }
.pay { cursor: pointer; position: relative; }
.pay input { position: absolute; opacity: 0; pointer-events: none; }
.pay span {
  display: block; text-align: center; padding: 9px 16px; border-radius: 6px; white-space: nowrap;
  border: 1.5px solid var(--c-border-strong); font-size: 0.86rem; font-weight: 600; color: var(--c-text-2);
  transition: border-color 0.15s, background 0.15s, color 0.15s;
}
.pay:hover span { border-color: #9cc9e0; }
.pay input:checked + span { border-color: var(--c-primary); background: var(--c-primary-soft); color: var(--c-primary-darker); }
.pay input:focus-visible + span { outline: 2px solid var(--c-primary); outline-offset: 2px; }

/* Récapitulatif */
.summary { padding: 20px; }
.summary-head { padding-bottom: 14px; margin-bottom: 14px; border-bottom: 1px solid var(--c-border); }
.summary-client { font-weight: 650; color: var(--c-muted); font-size: 1rem; overflow-wrap: anywhere; }
.summary-client.set { color: var(--c-text); }
.checklist { list-style: none; margin: 0 0 14px; padding: 0; display: flex; gap: 6px; flex-wrap: wrap; }
.checklist li {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 6px;
  border-radius: 999px; font-size: 0.78rem; font-weight: 600;
  background: var(--c-surface-2); color: var(--c-muted); border: 1px solid var(--c-border);
}
.checklist .tick { width: 14px; height: 14px; border-radius: 50%; border: 1.5px solid currentColor; }
.checklist li.ok { background: var(--c-success-soft); color: var(--c-success); border-color: #c4ecd3; }
.checklist li.ok .tick { background: var(--c-success); border-color: var(--c-success); }
.summary .totals-panel { padding: 12px 14px; }
.summary .total-row { font-size: 0.88rem; }
.summary .total-row.grand { font-size: 1.05rem; }
.summary .total-row.due { font-size: 1.15rem; padding: 14px; }
.summary .total-row.due small { font-size: 0.72rem; font-weight: 600; opacity: 0.8; }
.discount-input { display: flex; }
.discount-input .input { padding: 5px 8px; font-size: 0.86rem; }
.discount-input .input:first-child { width: 90px; text-align: right; border-top-right-radius: 0; border-bottom-right-radius: 0; }
.discount-input select.input { width: 58px; border-left: 0; border-top-left-radius: 0; border-bottom-left-radius: 0; padding-right: 22px; background-position: right 4px center; background-color: var(--c-surface-2); }
.link-btn { border: 0; background: none; color: var(--c-primary); font-family: inherit; font-size: 0.82rem; font-weight: 600; cursor: pointer; padding: 8px 0 2px; }
.link-btn:hover { text-decoration: underline; }
.atx-row { display: grid; grid-template-columns: 60px minmax(0, 1fr) 78px 46px 30px; gap: 4px; padding: 6px 0; border-top: 1px dashed var(--c-border); }
.atx-row .input { padding: 5px 6px; font-size: 0.8rem; }
.atx-row .icon-btn { width: 30px; height: 30px; }
.summary-actions { display: flex; flex-direction: column; gap: 10px; margin-top: 16px; }
.summary-actions .hint { margin: 2px 0 0; }

.spinner {
  width: 15px; height: 15px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.45); border-top-color: #fff;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.composer-mobilebar { display: none; }

/* Fenêtre modale */
.modal {
  border: 0; padding: 0; border-radius: 10px; width: min(560px, calc(100vw - 32px));
  box-shadow: var(--shadow-lg); color: var(--c-text);
}
.modal::backdrop { background: rgba(10, 22, 40, 0.5); backdrop-filter: blur(2px); }
.modal-body { padding: 22px 24px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h2 { margin: 0; font-size: 1.15rem; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

@media (max-width: 1200px) {
  .composer { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 1024px) {
  .composer { grid-template-columns: minmax(0, 1fr); }
  .composer-side { position: static; }
  .composer-mobilebar {
    display: flex; align-items: center; justify-content: space-between; gap: 12px;
    position: sticky; bottom: 0; z-index: 35; margin: 0 -32px -40px;
    padding: 12px 32px; background: rgba(255, 255, 255, 0.95); backdrop-filter: blur(8px);
    border-top: 1px solid var(--c-border); box-shadow: 0 -6px 16px rgba(15, 31, 46, 0.06);
  }
  .composer-mobilebar > div { display: flex; flex-direction: column; line-height: 1.2; }
  .composer-mobilebar strong { font-size: 1.15rem; font-variant-numeric: tabular-nums; }
}
@media (max-width: 640px) {
  .choice-grid { grid-template-columns: minmax(0, 1fr); }
  .choice-body { flex-direction: row; align-items: center; flex-wrap: wrap; column-gap: 12px; }
  .choice-icon { margin-bottom: 0; }
  .choice-desc { flex-basis: 100%; padding-left: 48px; margin-top: -6px; }
  .composer-mobilebar { margin: 0 -16px -32px; padding: 12px 16px; }
  .step-head { flex-wrap: wrap; }
  .step-head > div { flex-basis: calc(100% - 46px); }
  .step-head .step-action { margin-left: 46px; }
}

/* ==========================================================================
   Barre latérale repliable (ordinateur) : rail d'icônes, ouverture au survol
   ou au focus clavier, par-dessus le contenu (sans le décaler).
   ========================================================================== */
@media (min-width: 1025px) {
  :root { --sidebar-rail: 76px; }
  .shell-main { margin-left: var(--sidebar-rail); }

  .sidebar {
    width: var(--sidebar-rail);
    overflow: hidden;
    transition: width 0.22s ease 0.12s, box-shadow 0.22s ease 0.12s;
  }
  .sidebar:hover,
  .sidebar:focus-within {
    width: var(--sidebar-w);
    box-shadow: 14px 0 36px rgba(10, 22, 40, 0.28);
    transition-delay: 0.05s;
  }

  /* Positions fixes des icônes : identiques replié / déplié (pas de saut). */
  .sidebar-brand { padding: 22px 17px 18px; }
  .sidebar-cta { justify-content: flex-start; padding: 10px 0 10px 18px; white-space: nowrap; overflow: hidden; }
  .sidebar-cta svg, .logout-btn { flex-shrink: 0; }
  .sidebar-nav { overflow-x: hidden; }
  .nav-link { padding: 9px 16px; white-space: nowrap; }
  .sidebar-footer { padding: 14px 20px; }
  .nav-section { white-space: nowrap; }

  .sidebar .brand-text,
  .sidebar .nav-link span,
  .sidebar .cta-label,
  .sidebar .user-meta,
  .sidebar .logout-btn {
    opacity: 0;
    transition: opacity 0.12s ease;
    white-space: nowrap;
  }
  .sidebar:hover .brand-text,
  .sidebar:hover .nav-link span,
  .sidebar:hover .cta-label,
  .sidebar:hover .user-meta,
  .sidebar:hover .logout-btn,
  .sidebar:focus-within .brand-text,
  .sidebar:focus-within .nav-link span,
  .sidebar:focus-within .cta-label,
  .sidebar:focus-within .user-meta,
  .sidebar:focus-within .logout-btn {
    opacity: 1;
    transition-delay: 0.12s;
  }

  /* Titres de section : remplacés par un simple séparateur une fois replié. */
  .sidebar:not(:hover):not(:focus-within) .nav-section {
    color: transparent;
    position: relative;
  }
  .sidebar:not(:hover):not(:focus-within) .nav-section::after {
    content: "";
    position: absolute;
    left: 14px;
    width: 26px;
    bottom: 10px;
    border-top: 1px solid rgba(255, 255, 255, 0.14);
  }
}

/* ==========================================================================
   Avoir : lignes reprises de la facture d'origine
   ========================================================================== */
.credit-banner {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 11px 14px;
  border-radius: 6px;
  background: var(--c-credit-soft);
  border: 1px solid var(--c-credit-border);
  color: var(--c-credit);
  font-size: 0.86rem;
}
.credit-banner svg { flex-shrink: 0; margin-top: 1px; }

.credit-line .line-designation,
.credit-line .line-price,
.credit-line .line-classification,
.credit-line .line-discount-value,
.credit-line select:disabled {
  background: var(--c-surface-2);
  color: var(--c-text-2);
  cursor: default;
  opacity: 1;
}
.credit-line .line-designation:focus,
.credit-line .line-price:focus { box-shadow: none; border-color: var(--c-border-strong); }
.stepper button:disabled { opacity: 0.35; cursor: not-allowed; background: var(--c-surface-2); color: var(--c-text-2); }

.removed-lines {
  margin-top: 14px;
  border: 1px dashed var(--c-border-strong);
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--c-surface-2);
}
.removed-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--c-muted);
  margin-bottom: 8px;
}
.removed-head .link-btn { padding: 0; text-transform: none; letter-spacing: 0; }
.removed-list { display: flex; flex-direction: column; gap: 6px; }
.removed-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 10px;
  border-radius: 6px;
  background: var(--c-surface);
  border: 1px solid var(--c-border);
}
.removed-name { flex: 1; min-width: 0; color: var(--c-muted); text-decoration: line-through; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.removed-qty { color: var(--c-muted); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* Ajustements petits écrans (en fin de fichier pour primer sur les règles de base) */
@media (max-width: 640px) {
  .welcome { padding: 22px 20px; }
  .quick-grid { grid-template-columns: minmax(0, 1fr); }
  .page-header h1 { font-size: 1.35rem; }
  .kpi .kpi-value { font-size: 1.45rem; }
}

/* ==========================================================================
   Impression
   ========================================================================== */
@media print {
  .sidebar, .sidebar-backdrop, .topbar, .footer, .no-print { display: none !important; }
  .shell-main { margin-left: 0 !important; }
  .content { padding: 0 !important; max-width: none; }
  body { background: #fff; }
  .card { box-shadow: none; border: none; }
  .invoice-doc-header { border-top: 5px solid var(--c-primary) !important; }
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}
.table td > a { white-space: nowrap; }
.cert-code { font-family: "Cascadia Code", Consolas, monospace; font-size: 0.72rem; color: var(--c-success); letter-spacing: 0.02em; margin-top: 2px; white-space: nowrap; }

/* Champs obligatoires & erreurs par champ */
.req-star { color: var(--c-danger); font-weight: 700; margin-left: 2px; }
.form-legend { font-size: 0.82rem; color: var(--c-muted); margin: 0 0 16px; }
.field-error { color: var(--c-danger); font-size: 0.8rem; margin: 5px 0 0; display: flex; gap: 6px; align-items: flex-start; }
.field-error::before { content: "!"; flex-shrink: 0; width: 15px; height: 15px; border-radius: 50%; background: var(--c-danger); color: #fff; font-size: 0.68rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; margin-top: 1px; }

/* Escompte supérieur au Total TTC */
.input.is-invalid { border-color: var(--c-danger); box-shadow: 0 0 0 3px rgba(185, 28, 28, 0.15); }

/* Lignes de débours (hors TVA, hors chiffre d'affaires) */
.item-row.debours-line { border-left: 3px solid var(--c-border-strong); background: var(--c-surface-2); }
.debours-check { display: flex; align-items: center; gap: 8px; font-weight: 600; cursor: pointer; }
.debours-check input { width: 16px; height: 16px; }

/* Groupes de lignes : interventions / débours */
.lines-empty-top { margin-top: 16px; border: 1px dashed var(--c-border-strong); border-radius: 8px; }
.line-group { margin-top: 20px; }
.line-group-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.line-group-title { margin: 0; font-size: 0.82rem; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--c-text); }
.line-group-sub { margin: 2px 0 0; font-size: 0.8rem; color: var(--c-muted); }
.line-group-sum { display: flex; align-items: baseline; gap: 10px; font-size: 0.82rem; color: var(--c-muted); white-space: nowrap; }
.line-group-sum strong { font-size: 1rem; color: var(--c-text); font-variant-numeric: tabular-nums; }
.line-group .lines-wrap { margin-top: 0; }
.group-empty { padding: 14px 16px; font-size: 0.85rem; color: var(--c-muted); text-align: center; }
.line-group-debours .line-group-title { color: var(--c-text-2); }
.line-group-debours .lines-wrap { background: var(--c-surface-2); }
.line-group-debours .item-row.debours-line { border-left: 0; background: transparent; }
.line-group-foot { display: flex; flex-direction: column; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--c-border); background: var(--c-surface); }
.line-group-foot > .line-group-sum { justify-content: flex-end; }
.commission-toggle { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border: 1px solid var(--c-border); border-radius: 8px; cursor: pointer; }
.commission-toggle input { width: 16px; height: 16px; flex-shrink: 0; }
.commission-toggle > span { flex: 1; display: flex; flex-direction: column; font-size: 0.88rem; }
.commission-toggle small { color: var(--c-muted); font-size: 0.76rem; }
.commission-toggle .commission-amount { font-variant-numeric: tabular-nums; color: var(--c-muted); }
.commission-toggle.on { border-color: var(--c-primary-border); background: var(--c-primary-soft); }
.commission-toggle.on .commission-amount { color: var(--c-text); }
.commission-toggle:has(input:disabled) { opacity: 0.6; cursor: not-allowed; }

/* Fiche facture : intertitres de groupe dans le tableau */
.table tr.group-row td { background: var(--c-surface-2); font-size: 0.75rem; font-weight: 750; letter-spacing: 0.06em; text-transform: uppercase; color: var(--c-text-2); }
.table tr.group-sum td { font-weight: 600; border-top: 1px solid var(--c-border-strong); }

/* Dossier de transit (facultatif) */
.shipment-box { margin-top: 12px; border: 1px solid var(--c-border); border-radius: 8px; padding: 10px 14px; }
.shipment-box summary { cursor: pointer; font-weight: 650; font-size: 0.9rem; color: var(--c-text-2); }
.shipment-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0 14px; margin-top: 12px; }
@media (max-width: 760px) { .shipment-grid { grid-template-columns: minmax(0, 1fr); } }

/* Bouton d'ajout en bas de chaque bloc de lignes */
.group-add {
  display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 11px 16px; border: 0; border-top: 1px dashed var(--c-border-strong);
  background: var(--c-surface); color: var(--c-primary); font: inherit; font-weight: 650; font-size: 0.88rem; cursor: pointer;
}
.group-add:hover { background: var(--c-primary-soft); }
.group-add:focus-visible { outline: 2px solid var(--c-primary); outline-offset: -2px; }
.group-add[hidden] { display: none; }
.line-group + .line-group { margin-top: 24px; }
