/* ============================================================
   Facturation — direction « Blue Glass »
   Implémentation des tokens et composants décrits dans design.md.
   Cible desktop 1440×900, dégradation propre jusqu'à 1200 px.
   ============================================================ */

:root {
  /* --- Ambient --- */
  --ambient: linear-gradient(160deg, #EFF5FC 0%, #D8E8F7 38%, #B9D5EF 72%, #9BC2E6 100%);

  /* --- Encre --- */
  --ink-900: #0A1F3C;
  --ink-700: #24456E;
  --ink-500: #4A6B96;
  --ink-400: #7794B8;
  --ink-on-deep: #FFFFFF;
  --ink-on-deep-soft: #A9C7E6;

  /* --- Marque --- */
  --brand-900: #0C2E52;
  --brand-800: #123C6B;
  --brand-700: #1B4E86;
  --brand-600: #2264A8;
  --brand-500: #2E7BC4;
  --brand-400: #5C9BD8;
  --brand-300: #8FC0E8;
  --brand-200: #C0DBF3;
  --brand-100: #E2EEFA;

  /* --- Sémantique --- */
  --positive: #10A885;  --positive-ink: #06705B;
  --negative: #D63A4A;  --negative-ink: #A62633;
  --caution:  #C48C14;  --caution-ink:  #8A5A00;

  /* --- Verre --- */
  --glass-frost-bg: rgba(255, 255, 255, 0.55);
  --glass-frost-border: rgba(255, 255, 255, 0.70);
  --glass-frost-blur: blur(28px) saturate(150%);

  --glass-sheet-bg: rgba(255, 255, 255, 0.88);
  --glass-sheet-border: rgba(255, 255, 255, 0.85);
  --glass-sheet-blur: blur(20px) saturate(120%);

  --glass-deep-bg: linear-gradient(150deg, #16436F 0%, #0C2E52 100%);
  --glass-deep-border: rgba(143, 192, 232, 0.28);

  --sheen: inset 0 1px 0 rgba(255, 255, 255, 0.75);
  --sheen-deep: inset 0 1px 0 rgba(255, 255, 255, 0.16);

  /* --- Règles (jamais de bordure sombre) --- */
  --rule: rgba(12, 46, 82, 0.10);
  --rule-soft: rgba(12, 46, 82, 0.06);

  /* --- Élévation : ombres bleues, jamais noires --- */
  --shadow-xs: 0 1px 2px rgba(12, 46, 82, 0.06);
  --shadow-sm: 0 2px 8px rgba(12, 46, 82, 0.07), 0 1px 2px rgba(12, 46, 82, 0.05);
  --shadow-md: 0 12px 28px -8px rgba(12, 46, 82, 0.16), 0 3px 8px -3px rgba(12, 46, 82, 0.10);
  --shadow-lg: 0 28px 60px -16px rgba(12, 46, 82, 0.26), 0 8px 20px -8px rgba(12, 46, 82, 0.14);
  --shadow-deep: 0 20px 44px -12px rgba(12, 46, 82, 0.42);

  /* --- Rayons --- */
  --r-xs: 8px;
  --r-sm: 12px;
  --r-md: 18px;
  --r-lg: 24px;
  --r-xl: 32px;
  --r-pill: 999px;

  /* --- Motion --- */
  --ease: cubic-bezier(0.2, 0.8, 0.3, 1);
  --t-fast: 140ms;
  --t-base: 220ms;
  --t-slow: 380ms;
}

* { box-sizing: border-box; }

/* ---------- L1 — Ambient ---------- */
body {
  margin: 0;
  min-height: 100vh;
  background: var(--ambient);
  background-attachment: fixed;
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, Arial, sans-serif;
  font-feature-settings: "cv11", "ss01";
  color: var(--ink-700);
  font-size: 14.5px;
  line-height: 22px;
  font-weight: 450;
  -webkit-font-smoothing: antialiased;
}

::selection { background: rgba(46, 123, 196, 0.25); }

.orb {
  position: fixed;
  border-radius: 50%;
  filter: blur(90px);
  pointer-events: none;
  z-index: -1;
}
.orb-1 { top: -12%; left: 8%; width: 620px; height: 620px; background: radial-gradient(circle, rgba(255, 255, 255, 0.75) 0%, transparent 68%); }
.orb-2 { bottom: -25%; right: -8%; width: 780px; height: 780px; background: radial-gradient(circle, rgba(46, 123, 196, 0.28) 0%, transparent 70%); }

a { color: var(--brand-600); text-decoration: none; font-weight: 600; }
a:hover { text-decoration: underline; }

h1, h2, h3 { color: var(--ink-900); }

:focus-visible {
  outline: none;
  border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(46, 123, 196, 0.35);
}

/* ---------- Shell + NavRail (L2) ---------- */
.app-shell { min-height: 100vh; display: flex; align-items: flex-start; }

.sidebar {
  width: 248px;
  min-width: 248px;
  margin: 20px;
  position: sticky;
  top: 20px;
  height: calc(100vh - 40px);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  background: var(--glass-frost-bg);
  backdrop-filter: var(--glass-frost-blur);
  -webkit-backdrop-filter: var(--glass-frost-blur);
  border: 1px solid var(--glass-frost-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md), var(--sheen);
}

.brand {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 6px 24px;
  border-bottom: 1px solid rgba(12, 46, 82, 0.08);
  margin-bottom: 16px;
}
.brand-mark {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: var(--r-sm);
  background: var(--glass-deep-bg);
  box-shadow: var(--sheen-deep);
  color: #fff;
}
.brand-name { font-size: 19px; line-height: 26px; font-weight: 650; letter-spacing: -0.01em; color: var(--ink-900); }

.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 11px 14px;
  border-radius: var(--r-sm);
  color: var(--ink-500);
  font-size: 14.5px; line-height: 22px; font-weight: 600;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.nav a:hover { background: rgba(255, 255, 255, 0.55); color: var(--ink-900); text-decoration: none; }
.nav a.active {
  background: var(--glass-deep-bg);
  color: var(--ink-on-deep);
  box-shadow: var(--shadow-sm);
}
.nav a.active::before {
  content: "";
  position: absolute; left: 0; top: 8px; bottom: 8px;
  width: 3px; border-radius: 2px; background: var(--brand-300);
}
.nav-icon { flex-shrink: 0; stroke-width: 1.75; }

.rail-foot {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(12, 46, 82, 0.08);
  font-size: 12.5px; line-height: 18px; color: var(--ink-400);
}

.view { flex: 1; min-width: 0; padding: 40px 32px 60px; }
.view-inner { max-width: 1240px; margin: 0 auto; }

/* ---------- Typographie ---------- */
.page-header { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 28px; }
.page-header h1 { margin: 0; font-size: 30px; line-height: 36px; font-weight: 700; letter-spacing: -0.02em; }
.page-header .header-actions { display: flex; align-items: center; gap: 12px; }

.breadcrumb { display: inline-block; font-size: 12.5px; line-height: 18px; color: var(--ink-500); font-weight: 600; margin-bottom: 4px; }
.breadcrumb:hover { color: var(--brand-600); }

h2 { font-size: 19px; line-height: 26px; font-weight: 650; letter-spacing: -0.01em; margin: 0 0 20px; }
h3 { font-size: 15px; line-height: 22px; font-weight: 650; letter-spacing: -0.005em; color: var(--ink-700); margin: 0 0 12px; }

.label {
  font-size: 11.5px; line-height: 16px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-500);
}
.caption { font-size: 12.5px; line-height: 18px; color: var(--ink-400); }
.muted { color: var(--ink-400); }
.text-right { text-align: right; }

/* ---------- MoneyDisplay ---------- */
.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.money .sym { font-size: 0.55em; font-weight: 600; opacity: 0.75; vertical-align: top; margin-right: 4px; }
.money .dec { opacity: 0.45; }
.money .code { font-size: 0.78em; font-weight: 600; opacity: 0.5; margin-left: 4px; }

/* ---------- GlassPanel (L3 par défaut) ---------- */
.panel {
  background: var(--glass-sheet-bg);
  backdrop-filter: var(--glass-sheet-blur);
  -webkit-backdrop-filter: var(--glass-sheet-blur);
  border: 1px solid var(--glass-sheet-border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm), var(--sheen);
  padding: 26px 28px;
  margin-bottom: 24px;
}
.panel.frost {
  background: var(--glass-frost-bg);
  backdrop-filter: var(--glass-frost-blur);
  -webkit-backdrop-filter: var(--glass-frost-blur);
  border-color: var(--glass-frost-border);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.panel-head h2 { margin: 0; }

.grid { display: grid; gap: 20px; margin-bottom: 24px; }
.grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.grid.hero-row { grid-template-columns: 1.35fr 1fr; }
/* Pile de tuiles de hauteur égale, alignée sur la hauteur de la carte héro. */
.tile-stack { display: flex; flex-direction: column; gap: 20px; }
.tile-stack > .stat { flex: 1; }
.grid.charts-row { grid-template-columns: 1.15fr 1fr; align-items: stretch; }
.grid .panel { margin-bottom: 0; }

/* ---------- HeroCard (L4) ---------- */
.hero {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-xl);
  padding: 32px 36px;
  background: var(--glass-deep-bg);
  border: 1px solid var(--glass-deep-border);
  box-shadow: var(--shadow-deep), var(--sheen-deep);
  color: var(--ink-on-deep);
  display: flex; flex-direction: column; justify-content: space-between;
  min-height: 260px;
}
.hero::before {
  content: "";
  position: absolute; inset: 0;
  background: radial-gradient(circle at 78% 0%, rgba(92, 155, 216, 0.45), transparent 60%);
  pointer-events: none;
}
.hero > * { position: relative; }
.hero .label { color: var(--ink-on-deep-soft); margin-bottom: 10px; }
.hero .hero-value {
  font-size: 56px; line-height: 60px; font-weight: 700;
  letter-spacing: -0.03em; color: var(--ink-on-deep);
}
.hero-chips { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 16px; }
.hero-actions { display: flex; flex-wrap: wrap; gap: 10px; margin-top: 24px; }

/* Bilan : répartition facturé / hors facture, sur fond profond. */
.hero-split-bar .track { display: flex; height: 10px; border-radius: var(--r-pill); overflow: hidden; background: rgba(255, 255, 255, 0.14); }
.hero-split-bar .track i { display: block; height: 100%; transition: width var(--t-slow) var(--ease); }
.hero-split-bar .keys { display: flex; flex-wrap: wrap; gap: 8px 20px; margin-top: 14px; }
.hero-split-bar .keys span { display: inline-flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 550; color: var(--ink-on-deep-soft); }
.hero-split-bar .keys i { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }

/* Bandeau chiffres horizontal (détail de facture) */
.hero.split { flex-direction: row; align-items: stretch; min-height: 148px; padding: 26px 36px 30px; gap: 0; }
.hero.split .hero-cell { flex: 1; padding: 0 28px; }
.hero.split .hero-cell:first-child { padding-left: 0; }
.hero.split .hero-cell + .hero-cell { border-left: 1px solid rgba(143, 192, 232, 0.22); }
.hero.split .hero-cell .value { font-size: 34px; line-height: 40px; font-weight: 700; letter-spacing: -0.025em; color: var(--ink-on-deep-soft); }
.hero.split .hero-cell.primary .value { font-size: 44px; line-height: 50px; letter-spacing: -0.03em; color: var(--ink-on-deep); }
.hero .hero-progress { position: absolute; left: 36px; right: 36px; bottom: 18px; }

/* ---------- DeltaChip ---------- */
.chip {
  display: inline-flex; align-items: center; gap: 5px;
  height: 26px; padding: 0 10px; border-radius: var(--r-pill);
  background: rgba(46, 123, 196, 0.12);
  font-size: 12.5px; font-weight: 600; color: var(--ink-700);
  white-space: nowrap;
}
.hero .chip { background: rgba(255, 255, 255, 0.18); color: var(--ink-on-deep); }
.chip.up svg { stroke: var(--positive); }
.chip.down svg { stroke: var(--negative); }

/* ---------- StatTile (L2) ---------- */
.stat {
  position: relative;
  overflow: hidden;
  border-radius: var(--r-md);
  padding: 20px 22px;
  min-height: 118px;
  background: var(--glass-frost-bg);
  backdrop-filter: var(--glass-frost-blur);
  -webkit-backdrop-filter: var(--glass-frost-blur);
  border: 1px solid var(--glass-frost-border);
  box-shadow: var(--shadow-sm), var(--sheen);
  display: flex; flex-direction: column; justify-content: space-between; gap: 6px;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.stat::before {
  content: "";
  position: absolute; left: 0; top: 0; bottom: 0; width: 3px;
  background: var(--brand-400);
  opacity: 0; transition: opacity var(--t-fast) var(--ease);
}
.stat:hover { transform: translateY(-2px); box-shadow: var(--shadow-md), var(--sheen); }
.stat:hover::before { opacity: 1; }
.stat .value {
  font-size: 34px; line-height: 40px; font-weight: 700;
  letter-spacing: -0.025em; color: var(--ink-900);
  font-variant-numeric: tabular-nums;
}
.stat.compact { min-height: 96px; }
.stat.compact .value { font-size: 26px; line-height: 32px; letter-spacing: -0.02em; }
.stat.alarm { background: rgba(214, 58, 74, 0.07); border-color: rgba(214, 58, 74, 0.18); }
.stat.alarm::before { background: var(--negative); opacity: 1; }

.progress { height: 8px; border-radius: var(--r-pill); background: rgba(12, 46, 82, 0.09); overflow: hidden; }
.progress > i {
  display: block; height: 100%; border-radius: var(--r-pill);
  background: linear-gradient(90deg, var(--brand-500), var(--positive));
  transition: width var(--t-slow) var(--ease);
}
.hero .progress { background: rgba(255, 255, 255, 0.18); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  height: 38px; padding: 0 16px;
  border-radius: var(--r-sm);
  border: 1px solid rgba(255, 255, 255, 0.9);
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink-700);
  font-family: inherit; font-size: 14.5px; font-weight: 600;
  white-space: nowrap; cursor: pointer;
  box-shadow: var(--shadow-sm), var(--sheen);
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
.btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md), var(--sheen); text-decoration: none; color: var(--ink-900); }
.btn:active { transform: translateY(0); }
.btn.primary {
  background: var(--glass-deep-bg);
  border-color: var(--glass-deep-border);
  color: var(--ink-on-deep);
  box-shadow: var(--shadow-md), var(--sheen-deep);
}
.btn.primary:hover { color: var(--ink-on-deep); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--ink-500); box-shadow: none; }
.btn.ghost:hover { background: rgba(255, 255, 255, 0.55); box-shadow: none; color: var(--ink-900); }
.btn.danger {
  background: rgba(214, 58, 74, 0.10);
  border-color: rgba(214, 58, 74, 0.28);
  color: var(--negative-ink);
  box-shadow: var(--shadow-xs);
}
.btn.danger:hover { background: rgba(214, 58, 74, 0.16); color: var(--negative-ink); }
/* Dans un tableau : toujours lisible, mais sans pastille rouge à chaque ligne. */
.btn.danger.quiet { background: transparent; border-color: transparent; box-shadow: none; }
.btn.danger.quiet:hover { background: rgba(214, 58, 74, 0.10); border-color: rgba(214, 58, 74, 0.28); }
.btn.small { height: 30px; padding: 0 12px; font-size: 13px; border-radius: var(--r-xs); }
.btn.large { height: 44px; padding: 0 20px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

/* Boutons posés sur une surface L4 */
.hero .btn {
  background: rgba(255, 255, 255, 0.14);
  border-color: rgba(255, 255, 255, 0.28);
  color: var(--ink-on-deep);
  box-shadow: var(--sheen-deep);
}
.hero .btn:hover { background: rgba(255, 255, 255, 0.22); color: var(--ink-on-deep); box-shadow: var(--sheen-deep); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; flex-shrink: 0;
  border-radius: 50%;
  border: 1px solid var(--glass-frost-border);
  background: var(--glass-frost-bg);
  backdrop-filter: var(--glass-frost-blur);
  -webkit-backdrop-filter: var(--glass-frost-blur);
  box-shadow: var(--shadow-sm);
  color: var(--ink-700);
  cursor: pointer;
  transition: transform var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.icon-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow-md); }

/* ---------- Segmented control ---------- */
.seg {
  display: inline-flex; gap: 2px; padding: 3px;
  background: var(--glass-frost-bg);
  backdrop-filter: var(--glass-frost-blur);
  -webkit-backdrop-filter: var(--glass-frost-blur);
  border: 1px solid var(--glass-frost-border);
  border-radius: var(--r-pill);
  box-shadow: var(--shadow-sm);
  flex-wrap: wrap;
}
.seg button {
  height: 30px; padding: 0 14px;
  border: none; border-radius: var(--r-pill);
  background: transparent; color: var(--ink-500);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer;
  transition: background var(--t-fast) var(--ease), color var(--t-fast) var(--ease);
}
.seg button:hover { color: var(--ink-900); }
.seg button.active {
  background: var(--glass-deep-bg);
  color: var(--ink-on-deep);
  box-shadow: var(--shadow-sm);
}
.seg button sup { font-size: 10px; opacity: 0.7; margin-left: 2px; }

/* ---------- StatusBadge ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  height: 24px; padding: 0 11px;
  border-radius: var(--r-pill);
  font-size: 12px; font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; opacity: 0.85; flex-shrink: 0; }
.badge.draft     { color: #4A6B96; background: rgba(74, 107, 150, 0.12); }
.badge.sent      { color: #1B4E86; background: rgba(46, 123, 196, 0.15); }
.badge.partial   { color: #8A5A00; background: rgba(196, 140, 20, 0.18); }
.badge.paid      { color: #06705B; background: rgba(16, 168, 133, 0.18); }
.badge.overdue   { color: #A62633; background: rgba(214, 58, 74, 0.16); }
.badge.cancelled { color: #7794B8; background: rgba(119, 148, 184, 0.12); }
.badge.accepted  { color: #06705B; background: rgba(16, 168, 133, 0.18); }
.badge.declined  { color: #A62633; background: rgba(214, 58, 74, 0.16); }
.badge.expired   { color: #7794B8; background: rgba(119, 148, 184, 0.12); }
/* Hors facture : « à encaisser » reprend l'ambre des impayés, « encaissé » le vert des payées. */
.badge.cash_due      { color: #8A5A00; background: rgba(196, 140, 20, 0.18); }
.badge.cash_received { color: #06705B; background: rgba(16, 168, 133, 0.18); }
/* Facture faite pour quelqu'un d'autre : violet, hors des couleurs de statut. */
.badge.owner         { color: #5B3FA8; background: rgba(110, 80, 200, 0.14); margin-left: 8px; }
.badge.owner::before { display: none; }

.pill {
  display: inline-flex; align-items: center; height: 22px; padding: 0 9px;
  border-radius: var(--r-pill);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--rule);
  font-size: 12px; font-weight: 600; color: var(--ink-500);
}

.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px; flex-shrink: 0;
  border-radius: 50%;
  background: rgba(46, 123, 196, 0.10);
  border: 1px solid rgba(46, 123, 196, 0.18);
  box-shadow: var(--sheen);
  font-size: 12px; font-weight: 650; color: var(--brand-700);
  letter-spacing: 0.02em;
}
.avatar.lg { width: 56px; height: 56px; font-size: 19px; }
.avatar.sm { width: 30px; height: 30px; font-size: 11px; }

/* --- Connexion et comptes --- */
.rail-who { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.rail-who-text { flex: 1; min-width: 0; }
.rail-who-name { font-size: 13.5px; line-height: 18px; font-weight: 600; color: var(--ink-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rail-who .caption { margin: 0; font-size: 11.5px; }
.rail-select {
  width: 100%; height: 34px; margin-bottom: 14px; padding: 0 10px;
  border-radius: var(--r-xs); border: 1px solid var(--glass-frost-border);
  background: rgba(255, 255, 255, 0.6); color: var(--ink-900); font: inherit; font-size: 13px; font-weight: 550;
}
body.auth-mode .sidebar { display: none; }
body.auth-mode .view { padding: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-wrap { width: 100%; display: flex; justify-content: center; padding: 40px 24px; }
.auth-card { width: 380px; max-width: 100%; }

/* ---------- DataTable (toujours sur L3) ---------- */
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left;
  padding: 0 10px 12px;
  font-size: 11.5px; line-height: 16px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-500);
  border-bottom: 1px solid var(--rule);
  white-space: nowrap;
}
/* Les lignes tiennent sur 50 px : rien ne passe à la ligne, les noms longs
   sont tronqués plutôt que de faire grandir la ligne. */
tbody td {
  padding: 14px 10px;
  font-size: 14.5px; line-height: 22px; color: var(--ink-700);
  border-bottom: 1px solid var(--rule-soft);
  white-space: nowrap;
}
tbody td.strong { max-width: 260px; overflow: hidden; text-overflow: ellipsis; }

/* Sous 1440 px un tableau large défile horizontalement dans son panneau
   plutôt que de déborder de la page. */
.table-wrap { overflow-x: auto; margin: 0 -4px; padding: 0 4px; }
tbody tr { transition: background var(--t-fast) var(--ease); }
tbody tr:hover { background: rgba(46, 123, 196, 0.06); }
tbody tr:hover td:first-child { border-top-left-radius: var(--r-sm); border-bottom-left-radius: var(--r-sm); }
tbody tr:hover td:last-child { border-top-right-radius: var(--r-sm); border-bottom-right-radius: var(--r-sm); }
tbody tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
tbody td.num { font-weight: 550; color: var(--ink-900); }
tbody td.strong { font-weight: 600; color: var(--ink-900); }
tbody td.late { color: var(--negative-ink); font-weight: 600; }
.caption.late { color: var(--negative-ink); font-weight: 600; }
.due-late { color: var(--negative-ink); font-weight: 600; display: inline-flex; align-items: center; gap: 6px; }
.due-late::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; }

.table-scroll { max-height: 620px; overflow-y: auto; margin: 0 -4px; padding: 0 4px; }
.table-scroll thead th { position: sticky; top: 0; z-index: 1; background: rgba(255, 255, 255, 0.94); backdrop-filter: blur(8px); }

.actions-cell { display: flex; gap: 2px; justify-content: flex-end; align-items: center; flex-wrap: nowrap; }
.actions-cell .btn.small { padding: 0 10px; }
/* Les actions non destructives s'estompent au repos ; « Supprimer » reste lisible. */
tbody .actions-cell .reveal { opacity: 0.35; transition: opacity var(--t-fast) var(--ease); }
tbody tr:hover .actions-cell .reveal { opacity: 1; }

.name-cell { display: flex; align-items: center; gap: 10px; }

.link-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  color: var(--ink-400); font-size: 15px; line-height: 1;
  transition: color var(--t-fast) var(--ease);
}
.link-btn:hover { color: var(--negative); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.toolbar .search-wrap { position: relative; flex: 1; min-width: 240px; }
.toolbar .search-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); pointer-events: none; color: var(--ink-400); }
.search-input {
  width: 100%; height: 38px;
  padding: 0 16px 0 38px;
  border-radius: var(--r-pill);
  border: 1px solid var(--rule);
  background: rgba(255, 255, 255, 0.75);
  font-family: inherit; font-size: 14.5px; color: var(--ink-900);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease);
}
.search-input::placeholder { color: var(--ink-400); }
.search-input:focus { outline: none; border-color: var(--brand-500); box-shadow: 0 0 0 3px rgba(46, 123, 196, 0.28); }

/* ---------- Formulaires ---------- */
.field { margin-bottom: 16px; }
form label, .field label {
  display: block; margin-bottom: 6px;
  font-size: 11.5px; line-height: 16px; font-weight: 600;
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-500);
}
form label .req { color: var(--negative); }
form input, form select, form textarea, .field input, .field select, .field textarea {
  width: 100%; height: 40px; padding: 0 12px;
  border: 1px solid rgba(12, 46, 82, 0.12);
  border-radius: var(--r-sm);
  background: rgba(255, 255, 255, 0.72);
  font-family: inherit; font-size: 14.5px; color: var(--ink-900);
  transition: border-color var(--t-fast) var(--ease), box-shadow var(--t-fast) var(--ease), background var(--t-fast) var(--ease);
}
form textarea, .field textarea { height: auto; padding: 10px 12px; resize: vertical; line-height: 22px; }
form input[type="file"] { height: auto; padding: 9px 12px; font-size: 13px; }
form input[type="checkbox"] { width: auto; height: auto; }
form input:focus, form select:focus, form textarea:focus,
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: var(--brand-500);
  box-shadow: 0 0 0 3px rgba(46, 123, 196, 0.28);
  background: #fff;
}
form input::placeholder, form textarea::placeholder, .field input::placeholder { color: var(--ink-400); }

.form-row { display: flex; gap: 16px; }
.form-row .field { flex: 1; min-width: 0; }

.form-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* ---------- LineItemsEditor ---------- */
.items-table thead th { padding: 0 8px 10px; }
.items-table tbody td { padding: 4px 4px; border-bottom: 1px solid var(--rule-soft); }
.items-table tbody tr:hover { background: transparent; }
.items-table input {
  height: 34px; padding: 0 8px;
  border-color: transparent; background: transparent;
  font-size: 14px;
}
.items-table input:hover { background: rgba(255, 255, 255, 0.6); border-color: var(--rule); }
.items-table input:focus { background: #fff; }
.items-table .desc-col { width: 40%; }
.items-table td.f-total { font-weight: 600; color: var(--ink-900); font-variant-numeric: tabular-nums; padding-right: 10px; }

/* ---------- TotalsBox (L2) ---------- */
.totals-box {
  max-width: 360px; margin-left: auto; margin-top: 20px;
  padding: 18px 20px;
  border-radius: var(--r-md);
  background: var(--glass-frost-bg);
  border: 1px solid var(--glass-frost-border);
  box-shadow: var(--shadow-xs), var(--sheen);
}
.totals-box .row {
  display: flex; justify-content: space-between; gap: 20px;
  padding: 5px 0; font-size: 14.5px; color: var(--ink-500);
}
.totals-box .row span:last-child { font-variant-numeric: tabular-nums; color: var(--ink-700); font-weight: 550; }
.totals-box .row.total {
  margin-top: 10px; padding-top: 12px;
  border-top: 1px solid var(--rule);
  font-size: 26px; line-height: 32px; font-weight: 700; letter-spacing: -0.02em; color: var(--ink-900);
}
.totals-box .row.total span:last-child { font-size: 26px; font-weight: 700; color: var(--ink-900); }
.totals-box .row.paid span:last-child { color: var(--positive-ink); }

/* ---------- Graphes ---------- */
.month-plot {
  position: relative;
  display: flex; align-items: flex-end; gap: 10px;
  height: 210px;
  flex: 1;
}
.month-plot .gridlines { position: absolute; inset: 0 0 22px; display: flex; flex-direction: column; justify-content: space-between; pointer-events: none; }
.month-plot .gridlines i { display: block; border-top: 1px solid rgba(12, 46, 82, 0.07); }
.month-plot .bar-col {
  flex: 1; min-width: 0; max-width: 44px; height: 100%;
  display: flex; flex-direction: column; align-items: center; justify-content: flex-end; gap: 6px;
}
.month-plot .bar-value {
  font-size: 12.5px; font-weight: 600; color: var(--ink-900);
  white-space: nowrap; font-variant-numeric: tabular-nums;
  opacity: 0; transition: opacity var(--t-fast) var(--ease);
}
.month-plot .bar-col.peak .bar-value, .month-plot .bar-col:hover .bar-value { opacity: 1; }
.month-plot .bar {
  width: 100%;
  border-radius: 8px 8px 0 0;
  background: linear-gradient(180deg, var(--brand-400), var(--brand-700));
  transition: height var(--t-slow) var(--ease);
}
.month-plot .bar.empty { background: rgba(12, 46, 82, 0.10); border-radius: 3px 3px 0 0; }
/* Bilan : barre empilée facturé (marque, en bas) + hors facture (ambre, au-dessus).
   overflow:hidden laisse l'arrondi du haut découper le segment supérieur, quel qu'il soit. */
.month-plot .bar.stack { background: none; display: flex; flex-direction: column; justify-content: flex-end; overflow: hidden; }
/* `bar-seg` et non `seg` : .seg est déjà le contrôle segmenté (pilule de 999px). */
.month-plot .bar.stack .bar-seg { display: block; width: 100%; flex-shrink: 0; border-radius: 0; }
.month-plot .bar.stack .bar-seg.cash { background: linear-gradient(180deg, #E0AC3A, var(--caution)); }
.month-plot .bar.stack .bar-seg.billed { background: linear-gradient(180deg, var(--brand-400), var(--brand-700)); }
.month-plot .bar.stack .bar-seg.archive { background: linear-gradient(180deg, #3ECBA8, var(--positive)); }

.chart-legend { display: flex; gap: 18px; margin-bottom: 18px; }
.chart-legend span { display: inline-flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 550; color: var(--ink-500); }
.chart-legend i { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.month-plot .axis-label {
  font-size: 12.5px; line-height: 18px; color: var(--ink-400);
  text-transform: capitalize; white-space: nowrap;
}
.month-plot.dense { gap: 5px; }
.month-plot.dense .bar-col:nth-child(even) .axis-label { visibility: hidden; }

/* --- Comparatif pluriannuel (Bilan) --- */
/* Les cartes partagent une échelle unique : la sparkline d'une année se lit par rapport au
   meilleur mois toutes années confondues, sinon une petite année paraît aussi forte qu'une
   grosse et le comparatif ne compare plus rien. */
.year-compare { display: grid; grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); gap: 16px; }
.year-card {
  border: 1px solid var(--rule); border-radius: var(--r-md); padding: 18px 18px 14px;
  background: var(--glass-sheet-bg); position: relative; transition: border-color var(--t-fast) var(--ease);
}
.year-card.current { border-color: var(--brand-300); box-shadow: 0 0 0 3px rgba(46, 123, 196, 0.10); }
.year-card .yc-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.year-card .yc-year { font-size: 15px; font-weight: 650; color: var(--ink-700); letter-spacing: -0.01em; }
.year-card .yc-total { font-size: 27px; line-height: 34px; font-weight: 680; letter-spacing: -0.025em; color: var(--ink-900); margin-top: 6px; }
.year-card .yc-meta { font-size: 12.5px; line-height: 18px; color: var(--ink-400); margin-top: 2px; }

.delta { font-size: 12px; font-weight: 620; padding: 3px 8px; border-radius: var(--r-pill); white-space: nowrap; }
.delta.up { color: var(--positive-ink); background: rgba(16, 168, 133, 0.13); }
.delta.down { color: var(--negative-ink); background: rgba(214, 58, 74, 0.12); }
.delta.flat { color: var(--ink-400); background: rgba(12, 46, 82, 0.07); }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 42px; margin: 14px 0 10px; }
.spark i {
  flex: 1; display: block; min-height: 2px; border-radius: 2px 2px 0 0;
  background: linear-gradient(180deg, var(--brand-300), var(--brand-500));
}
.spark i.void { background: rgba(12, 46, 82, 0.09); }

.split-mini { display: flex; height: 6px; border-radius: var(--r-pill); overflow: hidden; background: rgba(12, 46, 82, 0.07); }
.split-mini i { display: block; height: 100%; }
.split-mini i.billed { background: var(--brand-500); }
.split-mini i.cash { background: var(--caution); }
.split-mini i.archive { background: var(--positive); }
.year-card .yc-keys { display: flex; flex-wrap: wrap; gap: 4px 12px; margin-top: 9px; }
.year-card .yc-keys span { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; font-weight: 550; color: var(--ink-400); }
.year-card .yc-keys i { width: 8px; height: 8px; border-radius: 2px; flex-shrink: 0; }

.donut-wrap { display: flex; justify-content: center; margin-bottom: 20px; }
.donut { width: 200px; height: 200px; border-radius: 50%; position: relative; background: rgba(12, 46, 82, 0.08); }
.donut-hole {
  position: absolute; inset: 24px; border-radius: 50%;
  background: #FDFEFF;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  box-shadow: var(--shadow-xs);
}
.donut-hole .value { font-size: 19px; font-weight: 700; letter-spacing: -0.01em; color: var(--ink-900); }
.donut-hole .label { margin-top: 4px; font-size: 11px; }
.legend { display: flex; flex-direction: column; gap: 10px; }
.legend .row { display: flex; align-items: center; gap: 10px; }
.legend .dot { width: 9px; height: 9px; border-radius: 50%; flex-shrink: 0; }
.legend .name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-700); }
.legend .amount { font-weight: 550; color: var(--ink-900); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* ---------- AlertBanner ---------- */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 14px 18px; margin-bottom: 24px;
  border-radius: var(--r-md);
  background: rgba(196, 140, 20, 0.10);
  border: 1px solid rgba(196, 140, 20, 0.28);
  color: var(--ink-700);
}
.alert .icon { font-size: 18px; color: var(--caution-ink); line-height: 22px; flex-shrink: 0; }

/* ---------- Détail de document ---------- */
.detail-grid { display: grid; grid-template-columns: 1fr 340px; gap: 24px; align-items: start; }
.detail-side { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 24px; }
.detail-side .panel { margin-bottom: 0; }

.pay-card {
  border-radius: var(--r-md);
  padding: 14px 16px;
  background: var(--glass-frost-bg);
  border: 1px solid var(--glass-frost-border);
  box-shadow: var(--shadow-xs), var(--sheen);
}
.pay-card + .pay-card { margin-top: 12px; }
.pay-card .top { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pay-card .amount { font-size: 26px; line-height: 32px; font-weight: 700; letter-spacing: -0.02em; color: var(--positive-ink); margin: 6px 0 2px; }
.pay-card .bottom { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

.info-list { display: flex; flex-direction: column; gap: 4px; }

/* ---------- EmptyState ---------- */
.empty-state {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; padding: 56px 0; gap: 4px;
}
.empty-state .empty-icon {
  display: flex; align-items: center; justify-content: center;
  width: 56px; height: 56px; margin-bottom: 12px;
  border-radius: 50%;
  background: var(--glass-frost-bg);
  border: 1px solid var(--glass-frost-border);
  color: var(--brand-400);
}
.empty-state .title { font-size: 15px; line-height: 22px; font-weight: 650; color: var(--ink-700); }
.empty-state .sub { font-size: 12.5px; line-height: 18px; color: var(--ink-400); }
.empty-state.compact { padding: 28px 0; }

/* ---------- Modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(10, 31, 60, 0.42);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 24px;
  animation: fade-in var(--t-base) var(--ease);
}
.modal {
  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
  padding: 30px;
  border-radius: var(--r-xl);
  background: var(--glass-sheet-bg);
  backdrop-filter: var(--glass-sheet-blur);
  -webkit-backdrop-filter: var(--glass-sheet-blur);
  border: 1px solid var(--glass-sheet-border);
  box-shadow: var(--shadow-lg), var(--sheen);
  animation: pop-in var(--t-base) var(--ease);
}
.modal.wide { max-width: 800px; }
.modal h2 { margin-top: 0; font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

.lookup-box {
  padding: 16px 18px; margin-bottom: 20px;
  border-radius: var(--r-md);
  background: var(--glass-frost-bg);
  border: 1px solid var(--glass-frost-border);
  box-shadow: var(--sheen);
}
.lookup-box .field { margin-bottom: 0; }
.result-card {
  display: block; width: 100%; text-align: left;
  margin-top: 8px; padding: 10px 12px; height: auto;
  border-radius: var(--r-sm);
  border: 1px solid var(--glass-frost-border);
  background: rgba(255, 255, 255, 0.6);
  font-family: inherit; font-size: 13.5px; color: var(--ink-700);
  cursor: pointer;
  transition: background var(--t-fast) var(--ease);
}
.result-card:hover { background: #fff; }

/* ---------- Toast (L4) ---------- */
.toast {
  position: fixed; bottom: 24px; right: 24px; z-index: 100;
  padding: 13px 20px;
  border-radius: var(--r-md);
  background: var(--glass-deep-bg);
  color: var(--ink-on-deep);
  font-size: 14.5px; font-weight: 600;
  box-shadow: var(--shadow-deep), var(--sheen-deep);
  animation: toast-in var(--t-base) var(--ease);
}
.toast.error { background: linear-gradient(150deg, #B02A38, #8A1E2A); }
.toast.hidden { display: none; }

/* ---------- Motion ---------- */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop-in { from { opacity: 0; transform: translateY(10px) scale(0.985); } to { opacity: 1; transform: none; } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.view-inner > * { animation: rise var(--t-base) var(--ease) both; }
.view-inner > *:nth-child(2) { animation-delay: 40ms; }
.view-inner > *:nth-child(3) { animation-delay: 80ms; }
.view-inner > *:nth-child(4) { animation-delay: 120ms; }
.view-inner > *:nth-child(5) { animation-delay: 160ms; }
.view-inner > *:nth-child(n + 6) { animation-delay: 200ms; }
/* Re-rendu partiel (changement de période) : pas de nouvelle entrée en fondu. */
.view-inner.no-anim > * { animation: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-delay: 0ms !important;
    transition-duration: 0.01ms !important;
  }
}

/* ---------- Fallback sans backdrop-filter ---------- */
@supports not (backdrop-filter: blur(1px)) {
  .sidebar, .stat, .seg, .icon-btn, .totals-box, .pay-card, .lookup-box, .empty-state .empty-icon, .panel.frost { background: rgba(255, 255, 255, 0.94); }
  .panel, .modal { background: rgba(255, 255, 255, 0.96); }
}

/* ---------- Dégradation < 1200 px ---------- */
@media (max-width: 1200px) {
  .grid.hero-row, .grid.charts-row { grid-template-columns: 1fr; }
  .grid.cols-4 { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .detail-side { position: static; }
  .view { padding: 32px 24px 48px; }
}
