:root {
  /* Alias legacy → tokens DS (P11.3) : les noms historiques restent
     valides pour le code existant, les valeurs viennent du DS. */
  --bg: var(--ds-bg, #f6f7f5); --panel: var(--ds-surface, #ffffff);
  --ink: var(--ds-ink, #1d2622); --muted: var(--ds-muted, #66736c);
  --line: var(--ds-line, #dfe5e0); --accent: var(--ds-primary, #0f766e);
  --accent-ink: var(--ds-on-primary, #ffffff);
  --ok: var(--ds-success, #15803d); --warn: var(--ds-warning, #b45309);
  --bad: var(--ds-error, #b91c1c); --radius: var(--ds-r-m, 12px);
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--ds-font, "Inter", "Noto Sans Arabic", system-ui, sans-serif);
  background: var(--bg); color: var(--ink); font-size: 14px; }
a { color: var(--accent); text-decoration: none; }
button { font: inherit; cursor: pointer; }
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid var(--ds-line-input, var(--line));
  border-radius: 8px; background: var(--ds-surface, #fff); color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--ds-focus-ring, #0f766e); border-color: var(--accent); }
label { display: block; font-weight: 600; margin: 12px 0 4px; font-size: 13px; }
.boot { padding: 40px; text-align: center; color: var(--muted); }

.shell { display: flex; min-height: 100vh; }
/* Sidebar claire — Design System P11.3 (.ds-sidebar look) */
.sidebar { width: var(--ds-sidebar-w, 248px); background: var(--ds-surface, #fff);
  color: var(--ds-ink, #1d2622); border-inline-end: 1px solid var(--ds-line, #dfe5e0);
  padding: var(--ds-sp-4, 16px) var(--ds-sp-3, 12px);
  display: flex; flex-direction: column; gap: 2px; position: sticky; top: 0;
  height: 100vh; flex: none; }
.sidebar .brand { font-size: 19px; font-weight: 800; padding: 4px 10px 14px;
  display: flex; align-items: center; gap: 8px; }
/* P14.7 — logotype « balance » : tuile primary + glyphe SVG */
.logo-mark { width: 30px; height: 30px; border-radius: var(--ds-r-s, 8px); flex: none;
  background: var(--ds-primary, #0f766e); color: var(--ds-on-primary, #fff);
  display: inline-flex; align-items: center; justify-content: center; }
.logo-mark svg { width: 19px; height: 19px; display: block; }
.sidebar a { color: var(--ds-ink-2, #3e4a44); padding: 10px 12px; border-radius: var(--ds-r-m, 12px);
  display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 14px; }
.sidebar a .ds-icon { font-size: 20px; }
.sidebar a:hover { background: var(--ds-surface-2, #eff2f0); color: var(--ds-ink, #1d2622); }
.sidebar a.active { background: var(--ds-primary-soft, #e0f1ee); color: var(--ds-primary, #0f766e); }
.sidebar .spacer { flex: 1; }
.sidebar .who { padding: 10px; font-size: 12px; color: var(--ds-muted, #62705f);
  border-top: 1px solid var(--ds-line-2, #eaeee9); }
.main { flex: 1; padding: 24px 32px; max-width: 1200px; min-width: 0; }
/* Topbar-like context strip at top of content */
.page-context { display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  margin-bottom: 18px; }
.page-context .spacer { flex: 1; }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 16px; margin: 24px 0 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 18px; margin-bottom: 16px; }
.grid { display: grid; gap: 14px; }
.grid.cols-4 { grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.kpi .label { color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .04em; }
.kpi .value { font-size: 24px; font-weight: 700; margin-top: 4px;
  font-feature-settings: "tnum"; font-variant-numeric: tabular-nums; }
.kpi .sub { color: var(--muted); font-size: 12px; margin-top: 2px; }
table { width: 100%; border-collapse: collapse; background: var(--panel);
  border: 1px solid var(--line); border-radius: var(--ds-r-m, 12px); overflow: hidden; }
th, td { text-align: start; padding: 11px 14px; border-bottom: 1px solid var(--line); font-size: 13.5px; }
th { background: var(--ds-surface-2, #f9fafb); font-weight: 700; font-size: 11px;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr.clickable:hover { background: var(--ds-surface-2, #f9fafb); cursor: pointer; }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; }
.badge.ok { background: #dcfae6; color: var(--ok); }
.badge.warn { background: #fef0c7; color: var(--warn); }
.badge.bad { background: #fee4e2; color: var(--bad); }
.badge.muted { background: #eef2f6; color: var(--muted); }
.btn { background: var(--accent); color: var(--accent-ink); border: none;
  border-radius: var(--ds-r-m, 12px); min-height: 44px;
  padding: 10px 18px; font-weight: 600;
  box-shadow: 0 1px 2px rgba(16, 24, 20, .18); }
.btn:hover:not(:disabled) { background: var(--ds-primary-hover, #115e59);
  box-shadow: 0 2px 4px rgba(16, 24, 20, .22); }
.btn:active:not(:disabled) { box-shadow: none; transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ds-primary-soft, #e0f1ee); }
.btn.ghost { background: var(--ds-surface, #fff); color: var(--ink); border: 1px solid var(--line); }
.btn.danger { background: var(--bad); }
.btn.small { padding: 6px 13px; font-size: 13px; min-height: 36px; border-radius: var(--ds-r-s, 8px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > * { flex: 0 0 auto; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; align-items: end; }
.filters .field { min-width: 140px; }
.filters label { margin: 0 0 3px; }
.muted { color: var(--muted); }
.right { text-align: end; }
.num { font-variant-numeric: tabular-nums; }
/* Mixed-direction content (emails, codes, UUIDs, references) stays LTR. */
.ltr, bdi.ltr { direction: ltr; unicode-bidi: isolate; }
.num { unicode-bidi: isolate; }
/* Directional affordances flip under RTL. */
.go-arrow { display: inline-block; }
[dir="rtl"] .go-arrow { transform: scaleX(-1); }
.empty { padding: 30px; text-align: center; color: var(--muted); }
.error-box { background: #fee4e2; color: var(--bad); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.notice { background: var(--ds-primary-soft, #eff8ff); color: var(--ds-primary, #175cd3); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }
.warn-box { background: #fef0c7; color: var(--warn); border-radius: 8px; padding: 10px 14px; margin-bottom: 14px; }

.modal-bg { position: fixed; inset: 0; background: rgba(16,24,40,.5); display: flex;
  align-items: center; justify-content: center; z-index: 50; padding: 20px; }
.modal { background: var(--ds-surface, #fff); border-radius: var(--ds-r-xl, 20px); width: 100%; max-width: 560px;
  max-height: 90vh; overflow: auto; padding: 22px; }
.modal h3 { margin: 0 0 8px; }
.modal:focus { outline: none; }
.modal .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

#toast-root { position: fixed; bottom: 20px; inset-inline-end: 20px; z-index: 100; display: flex;
  flex-direction: column; gap: 8px; }
.toast { background: #101828; color: #fff; padding: 10px 16px; border-radius: 8px;
  font-size: 13px; box-shadow: 0 4px 12px rgba(0,0,0,.2); }
.toast.err { background: var(--bad); }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-card { width: 380px; }
.login-card .brand { font-size: 24px; font-weight: 800; text-align: center; margin-bottom: 4px; }
.login-card .sub { text-align: center; color: var(--muted); margin-bottom: 20px; }
.login-card h1.sub { font: inherit; margin: 0 0 20px; }
.login-lang { display: flex; justify-content: flex-end; margin-bottom: 8px; }
.lang-row { padding: 8px 10px 0; }

/* P14.5a — navigation groupée + menu profil global (D2) */
.nav-group { padding: 14px 12px 4px; font-size: 11px; font-weight: 700;
  letter-spacing: .05em; text-transform: uppercase; color: var(--ds-muted, #62705f); }
.topbar { display: none; }
.profile { position: relative; padding: 8px 10px 0; }
.profile-btn { display: flex; align-items: center; gap: 10px; width: 100%;
  padding: 8px; border: 0; border-radius: var(--ds-r-m, 12px); background: transparent;
  color: var(--ds-ink, #1d2622); font: inherit; text-align: start; cursor: pointer; }
.profile-btn:hover { background: var(--ds-surface-2, #eff2f0); }
.profile-btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ds-primary-soft, #e0f1ee); }
.avatar { width: 34px; height: 34px; border-radius: 50%; flex: none; display: grid;
  place-items: center; background: var(--ds-primary, #0f766e); color: var(--ds-on-primary, #fff);
  font-weight: 700; font-size: 15px; }
.avatar.lg { width: 42px; height: 42px; font-size: 17px; }
.profile-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; line-height: 1.3; }
.profile-meta strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-sub { font-size: 11px; color: var(--ds-muted, #62705f); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile-caret { color: var(--ds-muted, #62705f); flex: none; }
.profile-menu { position: absolute; inset-inline-end: 10px; bottom: calc(100% + 6px); z-index: 60;
  width: 260px; max-width: calc(100vw - 24px); padding: 10px;
  background: var(--ds-surface, #fff); border: 1px solid var(--ds-line, #dfe5e0);
  border-radius: var(--ds-r-m, 12px); box-shadow: 0 12px 32px rgba(0,0,0,.18); }
.profile-head { display: flex; gap: 10px; align-items: center; padding: 4px 4px 10px;
  border-bottom: 1px solid var(--ds-line, #dfe5e0); margin-bottom: 8px; }
.profile-head strong { display: block; font-size: 14px; }
.profile-head .muted { font-size: 12px; }
.profile-lang { padding: 2px 4px; }
.profile-lang .lang-select { width: 100%; }
.profile-logout { display: flex; align-items: center; gap: 8px; width: 100%;
  margin-top: 8px; padding: 9px 10px; border: 0; border-radius: var(--ds-r-s, 8px);
  background: transparent; color: var(--ds-error, #b3261e); font: inherit;
  cursor: pointer; text-align: start; }
.profile-logout:hover { background: var(--ds-surface-2, #eff2f0); }
.profile-logout:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ds-primary-soft, #e0f1ee); }

/* P14.5b — page Paramètres : sélecteur de thème */
.settings-card { max-width: 560px; }
.theme-picker { border: 0; margin: 12px 0 0; padding: 0; display: flex; gap: 10px; flex-wrap: wrap; }
.theme-picker legend { font-size: 13px; font-weight: 600; color: var(--ds-ink-2, #3e4a44); padding: 0; margin-bottom: 8px; }
.theme-opt { display: flex; align-items: center; gap: 8px; padding: 10px 16px;
  border: 1px solid var(--ds-line, #dfe5e0); border-radius: var(--ds-r-m, 12px);
  cursor: pointer; font-size: 14px; color: var(--ds-ink, #1d2622); }
.theme-opt:hover { background: var(--ds-surface-2, #eff2f0); }
.theme-opt:focus-within { box-shadow: 0 0 0 3px var(--ds-primary-soft, #e0f1ee); }
.theme-opt:has(input:checked) { border-color: var(--ds-primary, #0f766e);
  background: var(--ds-primary-soft, #e0f1ee); color: var(--ds-primary, #0f766e); font-weight: 600; }
.theme-opt input { accent-color: var(--ds-primary, #0f766e); width: 16px; height: 16px; }
.settings-note { margin: 14px 0 0; font-size: 13px; }
.lang-select { width: auto; padding: 4px 8px; font-size: 12px;
  background: var(--ds-surface-2, #fff); color: var(--ink); border-color: var(--ds-line-input); }
.lang-select option { background: var(--ds-surface, #fff); color: var(--ink); }
.modal { box-shadow: var(--ds-sh-3, 0 14px 36px rgba(20,30,25,.16)); }
[dir="rtl"] .modal .actions { justify-content: flex-start; }
.login-card .brand { display: flex; align-items: center; justify-content: center; gap: 8px; }
.login-card .brand .logo-mark { width: 34px; height: 34px; }
.login-card .brand .logo-mark svg { width: 22px; height: 22px; }
.tabs { display: flex; gap: 4px; margin-bottom: 16px; border-bottom: 1px solid var(--line); }
.tabs button { background: none; border: none; padding: 8px 14px; color: var(--muted); font-weight: 600; }
.tabs button.active { color: var(--accent); border-bottom: 2px solid var(--accent); }
.chart { display: flex; align-items: flex-end; gap: 4px; height: 140px; padding-top: 8px; }
.chart .bar { flex: 1; background: var(--ds-primary-soft, #b2ccff); border-radius: 3px 3px 0 0; min-height: 2px;
  position: relative; }
.chart .bar:hover { background: var(--accent); }
.chart .bar .tip { position: absolute; bottom: 100%; left: 50%; transform: translateX(-50%);
  background: #101828; color: #fff; font-size: 11px; padding: 3px 6px; border-radius: 4px;
  white-space: nowrap; display: none; }
.chart .bar:hover .tip { display: block; }
@media (max-width: 800px) {
  .shell { flex-direction: column; }
  .topbar { display: flex; align-items: center; justify-content: space-between;
    padding: 10px 14px; background: var(--ds-surface, #fff);
    border-bottom: 1px solid var(--ds-line, #dfe5e0); }
  .topbar .brand { font-size: 17px; font-weight: 800; display: flex; align-items: center; gap: 8px; }
  .topbar .brand .logo-mark { width: 26px; height: 26px; }
  .topbar .brand .logo-mark svg { width: 16px; height: 16px; }
  .topbar .profile { padding: 0; flex: none; }
  .topbar .profile-meta, .topbar .profile-sub, .topbar .profile-caret { display: none; }
  .topbar .profile-menu { top: calc(100% + 8px); bottom: auto; inset-inline-end: 0; width: min(280px, calc(100vw - 28px)); }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; flex-wrap: wrap; }
  .sidebar .brand, .sidebar .who, .sidebar .spacer, .sidebar .profile { display: none; }
  .sidebar .nav-group { flex-basis: 100%; padding: 10px 12px 2px; }
  .main { padding: 16px; overflow-x: auto; }
}

/* P13.6 — caption accessible masqué visuellement (tableaux) */
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

/* P14.4 — dark-theme overrides for legacy hardcoded colors */
[data-theme="dark"] .badge.ok { background: #14261B; }
[data-theme="dark"] .badge.warn { background: #2A2113; }
[data-theme="dark"] .badge.bad { background: #2E1518; }
[data-theme="dark"] .badge.muted { background: #232B27; }
[data-theme="dark"] .error-box { background: #2E1518; }
[data-theme="dark"] .warn-box { background: #2A2113; }
[data-theme="dark"] .notice { background: var(--ds-primary-soft); }
[data-theme="dark"] .modal-bg { background: rgba(0, 0, 0, 0.6); }
[data-theme="dark"] .chart .bar { background: var(--ds-primary-soft); }
[data-theme="dark"] .chart .bar:hover { background: var(--ds-primary); }
[data-theme="dark"] .toast { background: #0B0F0D; }
[data-theme="dark"] .toast.err { background: var(--ds-error); }
[data-theme="dark"] .logo-mark { color: var(--ds-on-primary, #06231F); }
[data-theme="dark"] .ds-btn--primary { box-shadow: 0 1px 2px rgba(0, 0, 0, .45); }

/* P14.4 — prefers-reduced-motion : neutralise animations non essentielles.
   Bonne pratique (WCAG 2.3.3 AAA) — pas une certification. */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
