/* =========================================================================
   Centre de Contrôle IA — Design System OPAYS (px-001b Visual Grammar)
   -------------------------------------------------------------------------
   Principes appliqués (PX-001B) :
   - R-01 Hiérarchie par le POIDS, jamais par couleur criarde.
   - R-02 Erreur présente sans agression (pas de rouge vif brutal).
   - R-03 Succès confirmé sans célébration (pas de vert néon).
   - R-05 / R-07 Respiration & rythme (espace généreux, pas de filets durs).
   - R-08 État toujours lisible (chargement / vide / erreur honnêtes).
   - R-09 Mouvement = confirmation d'état, jamais décoratif (reduced-motion).
   - R-10 Géométrie à échelle humaine (coins doux, air).
   - R-12 Cohérence : une seule grammaire sur tous les produits.
   Accessibilité (PX-008 / WCAG 2.2 AA) : contrastes >= 4.5:1, focus
   visible, navigation clavier, daltonisme (pas de rouge/vert seul).
   Police : Inter (texte) + Space Grotesk (titres) — « aligné Outfit/Inter ».
   ========================================================================= */

:root {
  /* Palette sombre mesurée — fond profond, pas de noir pur agressif */
  --bg: #0e1116;
  --bg-soft: #151a21;
  --surface: #1b2129;
  --surface-2: #232b35;
  --line: #2c3540; /* séparation douce, pas de filet dur */
  --text: #e8ecf1; /* contraste ~ 14:1 sur --bg */
  --text-dim: #a7b1bd; /* ~ 7:1 — OK AA pour texte secondaire */
  --text-faint: #7e8a98; /* ~ 4.6:1 — usage sur grandes tailles */

  /* Accents — teintes « signal » proportionnées (R-02/R-03), pas néon */
  --accent: #6ea8fe; /* bleu calme, confiance */
  --accent-soft: #2a3a52;
  --ok: #7fd1a6; /* vert sauge, succès sans excès */
  --ok-soft: #1f3a2e;
  --warn: #e6b873; /* ambre, échec sans agression */
  --warn-soft: #3a2f1c;
  --danger: #e88a8a; /* rouge atténué, erreur présente mais douce */
  --danger-soft: #3a2222;

  --radius: 14px;
  --radius-sm: 9px;
  --gap: 22px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.25);
  --ease: cubic-bezier(0.22, 0.61, 0.36, 1);
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(1200px 600px at 80% -10%, #18203033, transparent 60%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: "Outfit", "Inter", sans-serif; font-weight: 600; }

/* Accessibilité : lien d'évitement */
.skip-link {
  position: absolute;
  left: 12px;
  top: -48px;
  background: var(--surface);
  color: var(--text);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  z-index: 50;
  transition: top 0.2s var(--ease);
}
.skip-link:focus { top: 12px; }

.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;
}

/* --- Topbar ---------------------------------------------------------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 18px 28px;
  border-bottom: 1px solid var(--line);
  background: linear-gradient(180deg, #11161d, #0e1116);
  position: sticky;
  top: 0;
  z-index: 20;
}
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, var(--accent), #9b7bff);
  box-shadow: inset 0 0 0 1px #ffffff22;
}
.brand-text h1 { margin: 0; font-size: 18px; letter-spacing: 0.2px; }
.brand-sub { margin: 2px 0 0; color: var(--text-dim); font-size: 12.5px; }

.topbar-right { display: flex; align-items: center; gap: 14px; }
.badge {
  font-size: 12px; font-weight: 500;
  padding: 5px 10px; border-radius: 999px;
  border: 1px solid var(--line);
}
.badge-muted { color: var(--text-dim); }
.badge-live { color: var(--ok); border-color: #2f5a45; background: var(--ok-soft); }
.badge-mock { color: var(--warn); border-color: #5a4a2f; background: var(--warn-soft); }

.btn {
  font: inherit; font-size: 13.5px; font-weight: 500;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 8px 14px; border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.18s var(--ease), border-color 0.18s var(--ease);
}
.btn:hover { background: #2b3540; }
.btn:active { transform: translateY(1px); }

.live {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 0 #7fd1a655;
  animation: pulse 2.4s var(--ease) infinite;
}
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 #7fd1a655; }
  70% { box-shadow: 0 0 0 7px #7fd1a600; }
  100% { box-shadow: 0 0 0 0 #7fd1a600; }
}

/* --- Layout ---------------------------------------------------------- */
.layout {
  max-width: 1180px;
  margin: 0 auto;
  padding: 28px;
  display: grid;
  gap: var(--gap);
}

/* Filtres */
.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: end;
  gap: 18px 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
}
.field { display: flex; flex-direction: column; gap: 7px; }
.field > span, .field legend { font-size: 12.5px; color: var(--text-dim); padding: 0; }
.field select {
  font: inherit; color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 9px 12px; min-width: 180px;
}
.field-inline { border: 0; margin: 0; padding: 0; }
.radio { font-size: 13.5px; color: var(--text-dim); margin-right: 14px; }
.radio input { accent-color: var(--accent); }
.confidential-note {
  flex: 1 1 320px;
  margin: 0; font-size: 12.5px; color: var(--text-faint);
  border-left: 2px solid var(--accent-soft);
  padding-left: 12px;
}

/* KPI */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--gap);
}
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: var(--shadow);
}
.kpi { display: flex; flex-direction: column; gap: 6px; }
.kpi-label { margin: 0; font-size: 12.5px; font-weight: 500; color: var(--text-dim); text-transform: uppercase; letter-spacing: 0.6px; }
.kpi-value { margin: 0; font-size: 34px; font-weight: 600; font-family: "Outfit", sans-serif; line-height: 1.1; }
.kpi-meta { margin: 0; font-size: 12.5px; color: var(--text-faint); }

/* Cartes avec en-tête */
.card-head { margin-bottom: 16px; }
.card-head h2 { margin: 0; font-size: 16px; }
.card-sub { margin: 4px 0 0; font-size: 12.5px; color: var(--text-dim); }

/* Chart */
.chart-card { padding-bottom: 18px; }
.chart-wrap { width: 100%; }
.chart { width: 100%; height: 320px; display: block; }
.legend { display: flex; gap: 20px; margin-top: 10px; font-size: 12.5px; color: var(--text-dim); }
.legend-item { display: inline-flex; align-items: center; gap: 7px; }
.swatch { width: 12px; height: 12px; border-radius: 3px; display: inline-block; }
.swatch-ok { background: var(--ok); }
.swatch-fail { background: var(--warn); }

.bar { transition: width 0.5s var(--ease); }
.axis-line { stroke: var(--line); stroke-width: 1; }
.axis-text { fill: var(--text-faint); font-size: 11px; font-family: "Inter", sans-serif; }
.bar-ok { fill: var(--ok); }
.bar-fail { fill: var(--warn); }

/* Taux d'échec par capacité */
.two-col { display: grid; grid-template-columns: 1fr 1.2fr; gap: var(--gap); }
.barlist { list-style: none; margin: 0; padding: 0; display: grid; gap: 14px; }
.barlist li { display: grid; grid-template-columns: 150px 1fr 52px; align-items: center; gap: 12px; }
.barlist .cap-name { font-size: 13px; color: var(--text-dim); }
.barlist .track { height: 10px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.barlist .fill { height: 100%; border-radius: 999px; background: var(--warn); }
.barlist .pct { font-size: 12.5px; color: var(--text); text-align: right; font-variant-numeric: tabular-nums; }

/* Tableau d'audit */
.table-scroll { max-height: 360px; overflow: auto; border-radius: var(--radius-sm); }
.audit { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.audit caption { text-align: left; }
.audit th, .audit td { text-align: left; padding: 11px 12px; border-bottom: 1px solid var(--line); }
.audit thead th {
  position: sticky; top: 0;
  background: var(--surface-2);
  color: var(--text-dim); font-weight: 600; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.4px;
  z-index: 2;
}
.audit tbody tr { transition: background 0.15s var(--ease); }
.audit tbody tr:hover { background: #ffffff08; }
.audit td { color: var(--text); font-variant-numeric: tabular-nums; }

.tag { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 500; }
.tag-role { background: var(--accent-soft); color: #b9cdff; }
.tag-mode-shadow { background: #2a3140; color: var(--text-dim); }
.tag-mode-real { background: #243a30; color: var(--ok); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 7px; vertical-align: middle; }
.dot-ok { background: var(--ok); }
.dot-fail { background: var(--warn); }
.cell-ok { color: var(--ok); }
.cell-fail { color: var(--warn); }

/* Statut / états (R-08) */
.status-line { min-height: 20px; font-size: 13px; color: var(--text-dim); margin: 0; }
.status-line.err { color: var(--danger); }
.status-line.load { color: var(--text-faint); }

.empty {
  padding: 36px 18px; text-align: center; color: var(--text-faint);
  border: 1px dashed var(--line); border-radius: var(--radius-sm);
}

/* Focus visible (WCAG 2.4.7) */
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

/* Reduced motion (R-09) */
@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

@media (max-width: 900px) {
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .two-col { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .layout { padding: 16px; }
  .kpi-grid { grid-template-columns: 1fr; }
  .barlist li { grid-template-columns: 110px 1fr 48px; }
}
