/* AW Facture X — direction "Flow"
   Voir la charte graphique pour la justification des choix (palette validée
   ΔE/contraste, échelle typographique, tokens d'espacement). */

@font-face {
  font-family: 'Manrope';
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
  src: url('../fonts/manrope-variable.woff2') format('woff2-variations');
}
@font-face {
  font-family: 'JetBrains Mono';
  font-weight: 100 800;
  font-style: normal;
  font-display: swap;
  src: url('../fonts/jetbrains-mono-variable.woff2') format('woff2-variations');
}

:root {
  --violet-500: #6C5CE7;
  --violet-700: #4B3AC4;
  --amber-600:  #DB7A2F;
  --cyan-600:   #0B9FC7;
  --coral-600:  #D63384;
  --sky-600:    #2F7FE0;
  --good:    #1FAE6A;
  --warning: #E8A23D;
  --critical:#E5484D;

  --ink:      #17152A;
  --ink-soft: #38354F;
  --muted:    #6E6B87;
  --faint:    #9C99B4;
  --page:     #F6F5FB;
  --card:     #FFFFFF;
  --card-alt: #FBFAFE;
  --border:   #E8E6F3;
  --border-soft: #F0EEF9;
  --shadow-color: 250 40% 30%;

  --radius-sm: 8px;
  --radius-md: 14px;
  --radius-lg: 20px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --violet-500: #8B7CF6; --violet-700: #B4A9FA;
    --amber-600: #D67A38; --cyan-600: #1E93B5; --coral-600: #D6488E; --sky-600: #4C7BD1;
    --good: #34C87F; --warning: #F0B25A; --critical: #F2555B;
    --ink: #F1EFFA; --ink-soft: #D7D4EA; --muted: #A6A2C4; --faint: #6F6C8C;
    --page: #131120; --card: #1C1930; --card-alt: #211D3A;
    --border: #322D4E; --border-soft: #262239; --shadow-color: 250 60% 2%;
  }
}
:root[data-theme="dark"] {
  --violet-500: #8B7CF6; --violet-700: #B4A9FA;
  --amber-600: #D67A38; --cyan-600: #1E93B5; --coral-600: #D6488E; --sky-600: #4C7BD1;
  --good: #34C87F; --warning: #F0B25A; --critical: #F2555B;
  --ink: #F1EFFA; --ink-soft: #D7D4EA; --muted: #A6A2C4; --faint: #6F6C8C;
  --page: #131120; --card: #1C1930; --card-alt: #211D3A;
  --border: #322D4E; --border-soft: #262239; --shadow-color: 250 60% 2%;
}
:root[data-theme="light"] {
  --violet-500: #6C5CE7; --violet-700: #4B3AC4;
  --amber-600: #DB7A2F; --cyan-600: #0B9FC7; --coral-600: #D63384; --sky-600: #2F7FE0;
  --good: #1FAE6A; --warning: #E8A23D; --critical: #E5484D;
  --ink: #17152A; --ink-soft: #38354F; --muted: #6E6B87; --faint: #9C99B4;
  --page: #F6F5FB; --card: #FFFFFF; --card-alt: #FBFAFE;
  --border: #E8E6F3; --border-soft: #F0EEF9; --shadow-color: 250 40% 30%;
}

* { box-sizing: border-box; }
html { color-scheme: light dark; }
body {
  margin: 0;
  background: var(--page);
  color: var(--ink);
  font-family: 'Manrope', system-ui, sans-serif;
  font-weight: 500;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; }
.mono { font-family: 'JetBrains Mono', ui-monospace, monospace; font-variant-numeric: tabular-nums; }
h1, h2, h3 { font-family: 'Manrope', sans-serif; font-weight: 800; text-wrap: balance; margin: 0 0 var(--space-2); }
p { margin: 0 0 var(--space-3); }
:focus-visible { outline: 2px solid var(--violet-500); outline-offset: 2px; }

/* ---------- Brand mark ---------- */
.brand { display: flex; align-items: center; gap: var(--space-3); }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px; background: var(--violet-500);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.brand-mark svg { display: block; }
.brand-mark-logo { background: none; border-radius: 0; width: auto; max-width: 140px; }
.brand-mark-logo img { display: block; height: 100%; width: auto; max-width: 140px; object-fit: contain; }
.brand-word { font-weight: 800; font-size: 1.15rem; letter-spacing: -0.01em; white-space: nowrap; }
.brand-word span { color: var(--violet-500); }

/* ---------- Auth shell (login / 2FA) ---------- */
.auth-shell {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  padding: var(--space-5);
}
.auth-card {
  width: 100%; max-width: 380px; background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: var(--space-6);
  box-shadow: 0 4px 10px hsl(var(--shadow-color) / 0.10), 0 20px 40px hsl(var(--shadow-color) / 0.10);
}
.auth-card .brand { justify-content: center; margin-bottom: var(--space-5); }
.auth-card h1 { font-size: 1.3rem; text-align: center; }
.auth-card .lede { text-align: center; color: var(--muted); font-size: 0.9rem; margin-bottom: var(--space-5); }
.auth-secret {
  background: var(--card-alt); border: 1px dashed var(--border); border-radius: var(--radius-sm);
  padding: var(--space-3); text-align: center; margin-bottom: var(--space-4);
}
.auth-secret .mono { font-size: 1.05rem; letter-spacing: 2px; word-break: break-all; }
.auth-qr { display: flex; justify-content: center; margin-bottom: var(--space-4); }
.auth-qr img { border-radius: var(--radius-sm); border: 1px solid var(--border); }
.auth-footer { text-align: center; margin-top: var(--space-5); font-size: 0.85rem; color: var(--muted); }

/* ---------- Modale de détail facture ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: hsl(var(--shadow-color) / 0.55); z-index: 300;
  display: none; align-items: center; justify-content: center; padding: var(--space-5);
  opacity: 0; transition: opacity 0.2s ease;
}
.modal-overlay.is-open { display: flex; opacity: 1; }
.modal {
  background: var(--card); border-radius: var(--radius-lg); width: min(760px, 100%);
  max-height: 88vh; display: flex; flex-direction: column;
  box-shadow: 0 24px 64px hsl(var(--shadow-color) / 0.32);
  transform: translateY(10px) scale(0.98); transition: transform 0.2s cubic-bezier(.21,1.02,.73,1);
}
.modal-overlay.is-open .modal { transform: translateY(0) scale(1); }
.modal-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-4); padding: var(--space-5); border-bottom: 1px solid var(--border-soft); }
.modal-title { font-size: 1.15rem; font-weight: 800; }
.modal-subtitle { display: flex; gap: var(--space-3); align-items: center; flex-wrap: wrap; margin-top: 8px; font-size: 0.85rem; }
.modal-close { background: none; border: none; cursor: pointer; color: var(--faint); font-size: 0.85rem; padding: 8px; border-radius: var(--radius-sm); flex-shrink: 0; }
.modal-close:hover { color: var(--ink); background: var(--card-alt); }
.modal-body { padding: var(--space-5); overflow-y: auto; }
.modal-footer { padding: var(--space-4) var(--space-5); border-top: 1px solid var(--border-soft); display: flex; justify-content: flex-end; flex-shrink: 0; }
.modal-loading { color: var(--muted); text-align: center; padding: var(--space-6) 0; }

.origin-row { display: flex; align-items: center; gap: var(--space-4); flex-wrap: wrap; margin-bottom: var(--space-5); padding-bottom: var(--space-4); border-bottom: 1px solid var(--border-soft); }
.origin-item { display: flex; align-items: center; gap: 8px; font-size: 0.88rem; font-weight: 600; color: var(--ink-soft); }
.origin-badge {
  display: inline-flex; align-items: center; justify-content: center; width: 22px; height: 22px;
  border-radius: 50%; color: #fff; font-size: 0.7rem; font-weight: 800; flex-shrink: 0;
}
.modal-parties { display: grid; grid-template-columns: 1fr 1fr; gap: var(--space-5); margin-bottom: var(--space-5); }
.modal-party-label { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); margin-bottom: 4px; }
.modal-party-name { font-weight: 700; margin-bottom: 2px; }

.modal-totals { margin-top: var(--space-4); margin-left: auto; width: min(280px, 100%); }
.modal-totals > div { display: flex; justify-content: space-between; padding: 4px 0; color: var(--muted); }
.modal-total-ttc { font-weight: 800; font-size: 1.05rem; color: var(--ink); border-top: 1px solid var(--border); margin-top: 4px; padding-top: 8px; }
.modal-total-ttc span:last-child { color: var(--violet-700); }

body.modal-open { overflow: hidden; }

/* ---------- Formulaire éditable de l'avoir (dans la modale) ---------- */
.avoir-input {
  font-family: 'Manrope'; font-size: 0.85rem; padding: 5px 7px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card-alt); color: var(--ink); width: 100%;
}
.avoir-input:focus { outline: 2px solid color-mix(in srgb, var(--violet-500) 40%, transparent); outline-offset: 1px; }
.avoir-remove-ligne:hover { opacity: 0.7; }
#avoir-motif {
  font-family: 'Manrope'; font-size: 0.95rem; padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card-alt); color: var(--ink); width: 100%; resize: vertical;
}

@media (max-width: 640px) {
  .modal-parties { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) {
  .modal-overlay, .modal { transition: none; }
}

.logo-preview {
  width: 96px; height: 96px; flex-shrink: 0; display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--border); border-radius: var(--radius-md); background: var(--card-alt); padding: var(--space-2);
}
.logo-preview img { max-width: 100%; max-height: 100%; object-fit: contain; }

/* ---------- Form fields ---------- */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: var(--space-4); }
.field label { font-size: 0.8rem; font-weight: 700; color: var(--muted); }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="url"], .field input[type="number"] {
  font-family: 'Manrope'; font-size: 0.95rem; padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1px solid var(--border); background: var(--card-alt); color: var(--ink); width: 100%;
}
.field input.code-input {
  font-family: 'JetBrains Mono'; font-size: 1.5rem; letter-spacing: 6px; text-align: center;
}
.field .checkbox-row { display: flex; align-items: center; gap: 8px; font-size: 0.92rem; font-weight: 600; color: var(--ink-soft); }
.field-hint { font-size: 0.8rem; color: var(--faint); margin-top: -6px; }

.field-password { position: relative; }
.field-password input { padding-right: 44px; }
.field-password-toggle {
  position: absolute; top: 50%; right: 4px; transform: translateY(-50%);
  background: none; border: none; cursor: pointer; padding: 7px; border-radius: var(--radius-sm);
  color: var(--faint); display: flex; align-items: center; justify-content: center;
}
.field-password-toggle:hover { color: var(--ink); background: var(--card); }
.field-password-toggle .icon-eye-off { display: none; }
.field-password-toggle.is-visible .icon-eye { display: none; }
.field-password-toggle.is-visible .icon-eye-off { display: block; }

/* ---------- Buttons ---------- */
.btn {
  font-family: 'Manrope'; font-weight: 700; font-size: 0.9rem; border-radius: 999px;
  padding: 11px 22px; border: 1px solid transparent; cursor: pointer; display: inline-block;
  text-align: center; text-decoration: none; transition: transform 0.15s ease;
}
.btn-block { width: 100%; }
.btn-primary { background: var(--violet-500); color: #fff; box-shadow: 0 6px 16px hsl(var(--shadow-color) / 0.28); }
.btn-primary:hover { transform: translateY(-1px); }
.btn-secondary { background: var(--card); color: var(--ink); border-color: var(--border); }
.btn-ghost { background: transparent; color: var(--violet-500); border: none; padding: 8px 4px; }
.btn-danger { background: transparent; color: var(--critical); border-color: color-mix(in srgb, var(--critical) 35%, transparent); }
.btn-sm { padding: 7px 14px; font-size: 0.8rem; }
.btn:disabled { opacity: 0.7; cursor: default; }
.btn .cron-submit-icon { display: inline-block; margin-right: 4px; }
.btn.is-loading .cron-submit-icon { animation: btn-spin 0.8s linear infinite; }
@keyframes btn-spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .btn.is-loading .cron-submit-icon { animation: none; }
}

.testmode-banner {
  background: var(--warning); color: #201400; font-weight: 700; font-size: 0.85rem;
  text-align: center; padding: 9px 16px; position: sticky; top: 0; z-index: 20;
}
.testmode-banner a { color: #201400; text-decoration: underline; margin-left: 8px; }

/* ---------- App shell: sidebar + topbar ---------- */
.app-shell { display: flex; min-height: 100vh; }
.sidebar {
  width: 232px; flex-shrink: 0; background: var(--card); border-right: 1px solid var(--border);
  padding: var(--space-5) var(--space-4); display: flex; flex-direction: column;
  transition: width 0.2s ease;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-6); }
.sidebar .brand { padding-left: 4px; min-width: 0; }
.sidebar-toggle, .mobile-menu-toggle {
  background: none; border: none; cursor: pointer; color: var(--faint); padding: 7px; border-radius: 8px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
  transition: background 0.15s ease, color 0.15s ease;
}
.sidebar-toggle:hover, .mobile-menu-toggle:hover { background: var(--card-alt); color: var(--violet-500); }
.sidebar-toggle svg { transition: transform 0.25s ease; }
.mobile-menu-toggle { display: none; }
.nav-group-label {
  font-size: 0.68rem; font-weight: 700; letter-spacing: 0.09em; text-transform: uppercase;
  color: var(--faint); margin: var(--space-4) 0 var(--space-2) 4px; white-space: nowrap; overflow: hidden;
}
.nav-group-label:first-of-type { margin-top: 0; }
.navitem {
  display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius-sm);
  font-size: 0.88rem; font-weight: 600; color: var(--ink-soft); text-decoration: none; margin-bottom: 2px;
  transition: background 0.15s ease, color 0.15s ease;
}
.navitem .navicon {
  width: 22px; height: 22px; flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 7px; font-size: 0.95em;
  transition: transform 0.28s cubic-bezier(.34,1.56,.64,1), background 0.2s ease, color 0.2s ease;
}
.navlabel { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.navitem:not(.active):hover { color: var(--ink); background: var(--card-alt); }
.navitem:not(.active):hover .navicon {
  transform: scale(1.18) rotate(-6deg);
  background: color-mix(in srgb, var(--violet-500) 16%, transparent);
  color: var(--violet-500);
}
.navitem.active { background: var(--violet-500); color: #fff; }
.navitem.active .navicon { transform: scale(1.05); }
.sidebar-foot { margin-top: auto; padding-top: var(--space-4); border-top: 1px solid var(--border-soft); }
.app-version-sidebar {
  padding: 6px 12px 0; font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.7rem; color: var(--faint); font-variant-numeric: tabular-nums;
}
.auth-card .app-version {
  margin-top: var(--space-5); padding-top: var(--space-4); border-top: 1px solid var(--border-soft);
  text-align: center; font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.72rem; color: var(--faint); font-variant-numeric: tabular-nums;
}

.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--space-4);
  padding: var(--space-4) var(--space-6); border-bottom: 1px solid var(--border); background: var(--card);
}
.topbar-left { display: flex; align-items: center; gap: var(--space-3); min-width: 0; }
.topbar h1 { font-size: 1.25rem; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-user { display: flex; align-items: center; gap: var(--space-3); font-size: 0.85rem; flex-shrink: 0; }
.topbar-user .role-badge {
  font-size: 0.7rem; font-weight: 700; color: var(--violet-700); background: color-mix(in srgb, var(--violet-500) 14%, transparent);
  padding: 3px 9px; border-radius: 999px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%; background: var(--violet-500); color: #fff;
  display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 0.85rem; flex-shrink: 0;
}

/* ---------- Compte à rebours de session (topbar, haut à gauche) ---------- */
.session-timer {
  display: flex; align-items: center; gap: 6px; font-family: 'JetBrains Mono', ui-monospace, monospace;
  font-size: 0.78rem; font-weight: 700; font-variant-numeric: tabular-nums; letter-spacing: 0.02em;
  padding: 4px 10px; border-radius: 999px; flex-shrink: 0;
  color: var(--good); background: color-mix(in srgb, var(--good) 12%, transparent);
  border: 1px solid color-mix(in srgb, var(--good) 28%, transparent);
  transition: color 0.3s ease, background-color 0.3s ease, border-color 0.3s ease;
}
.session-timer-icon { font-size: 0.85rem; line-height: 1; }
.session-timer-unlimited {
  color: var(--violet-700); background: color-mix(in srgb, var(--violet-500) 12%, transparent);
  border-color: color-mix(in srgb, var(--violet-500) 26%, transparent);
}
.session-timer.session-timer-warning {
  color: var(--warning); background: color-mix(in srgb, var(--warning) 14%, transparent);
  border-color: color-mix(in srgb, var(--warning) 32%, transparent);
}
.session-timer.session-timer-critical {
  color: var(--critical); background: color-mix(in srgb, var(--critical) 16%, transparent);
  border-color: color-mix(in srgb, var(--critical) 36%, transparent);
  animation: session-timer-pulse 1s ease-in-out infinite;
}
@keyframes session-timer-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.55; }
}
@media (prefers-reduced-motion: reduce) {
  .session-timer.session-timer-critical { animation: none; }
}
@media (max-width: 640px) {
  .session-timer-icon { display: none; }
}
.content { padding: var(--space-6); width: 100%; }
.sidebar-backdrop { display: none; }

/* ---------- Sidebar repliée (desktop uniquement - cf. media queries plus bas) ---------- */
@media (min-width: 861px) {
  html.sidebar-collapsed .sidebar { width: 72px; }
  html.sidebar-collapsed .sidebar-head { justify-content: center; }
  html.sidebar-collapsed .brand-word,
  html.sidebar-collapsed .navlabel,
  html.sidebar-collapsed .nav-group-label { display: none; }
  html.sidebar-collapsed .navitem { justify-content: center; }
  html.sidebar-collapsed .sidebar-toggle svg { transform: rotate(180deg); }
}

/* ---------- Cards / tables / alerts ---------- */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md);
  padding: var(--space-5); margin-bottom: var(--space-5);
}
.card-title { font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--faint); margin-bottom: var(--space-4); }
.card > h2 { font-size: 1.1rem; margin-bottom: var(--space-2); }

.alert {
  display: flex; gap: var(--space-3); align-items: flex-start; padding: var(--space-4);
  border-radius: var(--radius-md); margin-bottom: var(--space-5); border: 1px solid transparent;
}
.alert-warning { background: color-mix(in srgb, var(--warning) 12%, var(--card)); border-color: color-mix(in srgb, var(--warning) 30%, transparent); }
.alert-error   { background: color-mix(in srgb, var(--critical) 10%, var(--card)); border-color: color-mix(in srgb, var(--critical) 28%, transparent); color: var(--critical); }
.alert-success { background: color-mix(in srgb, var(--good) 10%, var(--card)); border-color: color-mix(in srgb, var(--good) 28%, transparent); color: var(--good); }
.alert-icon { flex-shrink: 0; font-size: 1.1rem; line-height: 1.3; }
.alert-body { font-size: 0.9rem; }
.alert-body strong { display: block; margin-bottom: 2px; }
.alert ul { margin: 6px 0 0; padding-left: 18px; }
.alert a { font-weight: 700; text-decoration: underline; }

.table-scroll { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
table.data th {
  text-align: left; font-size: 0.7rem; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--faint); padding: 0 var(--space-3) var(--space-2); border-bottom: 1px solid var(--border);
}
table.data td { padding: var(--space-3); border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }

.pivot-table th, .pivot-table td { text-align: right; white-space: nowrap; }
.pivot-table th:first-child, .pivot-table td:first-child { text-align: left; }
.pivot-site-header { text-align: center !important; border-left: 1px solid var(--border); color: var(--ink-soft) !important; font-size: 0.72rem !important; }
.pivot-canal-header { text-align: right !important; }
.pivot-value.pivot-subtotal { font-weight: 700; background: var(--card-alt); }
.pivot-value.pivot-total { font-weight: 800; background: color-mix(in srgb, var(--violet-500) 10%, transparent); color: var(--violet-700); }
.pivot-table td.pivot-subtotal, .pivot-table th.pivot-subtotal { border-left: 1px solid var(--border-soft); }
.pivot-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); border-bottom: none; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.76rem; font-weight: 700;
  padding: 5px 12px; border-radius: 999px; white-space: nowrap;
}
.pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.pill-good { background: color-mix(in srgb, var(--good) 16%, transparent); color: var(--good); }
.pill-warn { background: color-mix(in srgb, var(--warning) 18%, transparent); color: var(--warning); }
.pill-crit { background: color-mix(in srgb, var(--critical) 16%, transparent); color: var(--critical); }
.pill-neutral { background: var(--border-soft); color: var(--muted); }

.statcards { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: var(--space-4); margin-bottom: var(--space-5); }
.statcard { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); display: flex; flex-direction: column; gap: var(--space-2); }
.stat-badge { width: 34px; height: 34px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 0.95rem; }
.stat-label { font-size: 0.78rem; color: var(--muted); font-weight: 700; }
.stat-value { font-family: 'JetBrains Mono'; font-weight: 700; font-size: 1.4rem; }
.stat-delta { font-size: 0.76rem; font-weight: 700; min-height: 1em; }
.stat-delta.up { color: var(--good); }
.stat-delta.down { color: var(--critical); }
.stat-sub { font-size: 0.76rem; color: var(--faint); }
[data-skeleton] { color: transparent !important; position: relative; }
[data-skeleton]::before {
  content: ""; position: absolute; inset: 2px 30%; background: var(--border-soft);
  border-radius: 4px; animation: skeleton-pulse 1.3s ease-in-out infinite;
}
@keyframes skeleton-pulse { 0%, 100% { opacity: 0.5; } 50% { opacity: 1; } }

/* ---------- Charts ---------- */
.charts-row { display: grid; grid-template-columns: 1.4fr 1fr 1fr; gap: var(--space-4); margin-bottom: var(--space-5); align-items: stretch; }
.chart-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-4); display: flex; flex-direction: column; }
.chart-card .card-title { margin-bottom: var(--space-2); }
.chart-body { flex: 1; display: flex; align-items: center; justify-content: center; min-height: 168px; position: relative; }
.chart-donut-wrap { display: flex; flex-direction: column; align-items: center; gap: var(--space-3); width: 100%; }
.chart-empty { position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 0.8rem; color: var(--faint); padding: var(--space-3); }
.donut-seg { cursor: default; transition: opacity 0.15s ease; }
.donut-seg:hover { opacity: 0.82; }
.bar-mark { cursor: default; }
.legend { display: flex; flex-wrap: wrap; gap: var(--space-2) var(--space-3); justify-content: center; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 0.76rem; color: var(--muted); font-weight: 600; }
.legend-swatch { width: 9px; height: 9px; border-radius: 2px; flex-shrink: 0; }
.chart-tooltip {
  position: fixed; display: none; z-index: 100; pointer-events: none;
  background: var(--ink); color: var(--card); font-size: 0.76rem; font-weight: 600;
  padding: 7px 10px; border-radius: 8px; box-shadow: 0 6px 16px hsl(var(--shadow-color) / 0.3);
  line-height: 1.4; max-width: 200px;
}
.chart-tooltip strong { color: var(--card); }

@media (max-width: 860px) {
  .charts-row { grid-template-columns: 1fr; }
}

.text-muted { color: var(--muted); }
.text-faint { color: var(--faint); font-size: 0.85rem; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.row-actions { display: flex; gap: var(--space-2); align-items: center; }
.row-actions form { display: inline; }
.link-plain { color: var(--violet-500); font-weight: 700; text-decoration: none; font-size: 0.85rem; }
.link-plain:hover { text-decoration: underline; }
.back-link { display: inline-flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85rem; font-weight: 600; text-decoration: none; margin-bottom: var(--space-5); }
.back-link:hover { color: var(--ink); }

/* ---------- Toasts (notifications flottantes, haut droite) ---------- */
.toast-stack {
  position: fixed; top: calc(65px + var(--space-4)); right: var(--space-5); z-index: 200;
  display: flex; flex-direction: column; gap: var(--space-3);
  width: min(360px, calc(100vw - var(--space-5) * 2));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: var(--space-3);
  padding: var(--space-4); border-radius: var(--radius-md);
  background: var(--card); border: 1px solid var(--border);
  box-shadow: 0 4px 10px hsl(var(--shadow-color) / 0.12), 0 20px 40px hsl(var(--shadow-color) / 0.14);
  border-left: 4px solid var(--sky-600);
  opacity: 0; transform: translateX(24px) scale(0.98);
  transition: opacity 0.28s cubic-bezier(.21,1.02,.73,1), transform 0.28s cubic-bezier(.21,1.02,.73,1), margin-top 0.28s ease;
}
.toast-in { opacity: 1; transform: translateX(0) scale(1); }
.toast-out { opacity: 0; transform: translateX(24px) scale(0.98); margin-top: calc(-1 * var(--space-3)); }
.toast-icon { font-size: 1rem; line-height: 1.4; flex-shrink: 0; color: var(--sky-600); }
.toast-body { flex: 1; font-size: 0.88rem; line-height: 1.4; color: var(--ink-soft); }
.toast-close {
  background: none; border: none; cursor: pointer; color: var(--faint); font-size: 0.7rem;
  padding: 2px; line-height: 1; flex-shrink: 0; border-radius: 4px;
}
.toast-close:hover { color: var(--ink); background: var(--card-alt); }

.toast-success { border-left-color: var(--good); }
.toast-success .toast-icon { color: var(--good); }
.toast-warning { border-left-color: var(--warning); }
.toast-warning .toast-icon { color: var(--warning); }
.toast-critical { border-left-color: var(--critical); }
.toast-critical .toast-icon { color: var(--critical); }

@media (prefers-reduced-motion: reduce) {
  .toast { transition: opacity 0.15s linear; transform: none !important; }
}
@media (max-width: 480px) {
  .toast-stack { top: calc(56px + var(--space-3)); right: var(--space-3); left: var(--space-3); width: auto; }
}

@media (max-width: 860px) {
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 264px; z-index: 60;
    transform: translateX(-100%); transition: transform 0.25s ease;
    box-shadow: 10px 0 28px hsl(var(--shadow-color) / 0.22);
    overflow-y: auto;
  }
  html.sidebar-mobile-open .sidebar { transform: translateX(0); }
  /* Le bouton "«" reste visible DANS le tiroir (z-index du .sidebar > celui du
     fond assombri) et sert à le refermer - contrairement au hamburger du topbar,
     qui lui se retrouve sous le fond assombri une fois le tiroir ouvert et ne
     peut donc pas servir à refermer (cf. bug signalé : "on peut ouvrir mais pas
     rétracter"). */
  .sidebar-toggle { display: inline-flex; }
  html.sidebar-collapsed .sidebar-toggle svg { transform: none; }
  .mobile-menu-toggle { display: inline-flex; }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: hsl(250 40% 8% / 0.5);
    opacity: 0; pointer-events: none; transition: opacity 0.25s ease; z-index: 55;
  }
  html.sidebar-mobile-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
  .content { padding: var(--space-4); }
  .topbar { padding: var(--space-3) var(--space-4); }
  .topbar h1 { font-size: 1.05rem; }
}
