/* Design system Business Agent (#54, étendu #76) — tokens et composants de la
   charte validée specs/design/SKILL.md (2026-07-03). Source unique : toute
   couleur/espacement des écrans DOIT venir d'ici (zéro valeur en dur, #52).
   Refonte vague 1 (#74) : shell sidebar, boutons/inputs/tabs/modale/toast,
   tampon verdict, polices vendorées — plus JAMAIS de <style> par page. */

/* Polices vendorées (#76) — zéro CDN. Display : Bricolage Grotesque (OFL).
   Corps : Public Sans (OFL). Données chiffrées : ui-monospace. */
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/static/fonts/bricolage-grotesque-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}
@font-face {
  font-family: "Bricolage Grotesque";
  src: url("/static/fonts/bricolage-grotesque-700.woff2") format("woff2");
  font-weight: 700;
  font-display: swap;
}
@font-face {
  font-family: "Public Sans";
  src: url("/static/fonts/public-sans-400.woff2") format("woff2");
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: "Public Sans";
  src: url("/static/fonts/public-sans-600.woff2") format("woff2");
  font-weight: 600;
  font-display: swap;
}

:root {
  /* Neutres */
  --ba-bg: #f6f7f9;
  --ba-surface: #ffffff;
  --ba-border: #e3e5ec;
  --ba-text: #16324f;
  --ba-text-muted: #5c6b7a;

  /* Marque */
  --ba-primary: #16324f;
  --ba-accent: #0e7c66;

  /* Sémantique métier — la couleur EST de l'information */
  --ba-go: #1a7f37;
  --ba-nogo: #c62828;
  --ba-etudier: #9a6700;
  --ba-deadline-close: #c62828;
  --ba-deadline-soon: #9a6700;
  --ba-source-boamp: #1f75cb;
  --ba-source-ted: #6666c4;
  /* 5.2:1 sur texte blanc (WCAG AA) — le #d35400 d'origine plafonnait à 4.2 */
  --ba-source-codeur: #b84a00;

  /* Rythme */
  --ba-radius: 6px;
  --ba-gap: 8px;
  --ba-gap-lg: 16px;
  --ba-font: "Public Sans", -apple-system, "Segoe UI", Roboto, sans-serif;
  --ba-font-display: "Bricolage Grotesque", var(--ba-font);
  --ba-font-mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  /* Échelle typo (#76) : 12 / 13 / 14 / 16 / 20 / 28 */
  --ba-font-size-xs: 12px;
  --ba-font-size-dense: 13px;
  --ba-font-size: 14px;
  --ba-font-size-md: 16px;
  --ba-font-size-lg: 20px;
  --ba-font-size-xl: 28px;
  --ba-shadow: 0 1px 3px rgba(22, 50, 79, 0.08);

  /* Shell (#76) — le bleu nuit devient un matériau : fond de la sidebar */
  --ba-sidebar-bg: #16324f;
  --ba-sidebar-text: #c9d6e2;
  --ba-sidebar-muted: #7d93a8;
  --ba-sidebar-active: #ffffff;
  --ba-sidebar-active-bg: rgba(255, 255, 255, 0.09);
  --ba-sidebar-width: 220px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --ba-bg: #12181f;
    --ba-surface: #1a232d;
    --ba-border: #2a3542;
    --ba-text: #dce4ec;
    --ba-text-muted: #8fa0b0;
    --ba-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
    --ba-sidebar-bg: #0e1721;
    --ba-sidebar-text: #b7c5d3;
    --ba-sidebar-muted: #64798d;
  }
}

/* --- Badges sémantiques ---------------------------------------------------- */
.ba-badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border-radius: 12px;
  padding: 2px 10px;
  font-size: var(--ba-font-size-dense);
  font-weight: 600;
  color: #fff;
  white-space: nowrap;
}
.ba-badge--go { background: var(--ba-go); }
.ba-badge--nogo { background: var(--ba-nogo); }
.ba-badge--etudier { background: var(--ba-etudier); }
.ba-badge--muted { background: var(--ba-text-muted); }

/* Pastille source (toujours visible, #52) */
.ba-source {
  display: inline-block;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  color: #fff;
  text-transform: uppercase;
}
.ba-source--boamp { background: var(--ba-source-boamp); }
.ba-source--ted { background: var(--ba-source-ted); }
.ba-source--codeur { background: var(--ba-source-codeur); }

/* --- Jauge de score (jamais un chiffre nu : raison à côté) ------------------ */
.ba-score {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  font-weight: 700;
  color: #fff;
  background: var(--ba-etudier);
}
.ba-score--high { background: var(--ba-go); }
.ba-score--low { background: var(--ba-nogo); }
.ba-score__reason {
  margin-left: var(--ba-gap);
  color: var(--ba-text-muted);
  font-size: var(--ba-font-size-dense);
}

/* --- Barre « prêt à déposer » (checklist #27) -------------------------------- */
.ba-readiness {
  height: 6px;
  border-radius: 3px;
  background: var(--ba-border);
  overflow: hidden;
}
.ba-readiness__fill {
  height: 100%;
  background: var(--ba-accent);
  transition: width 0.25s ease;
}
.ba-readiness--danger .ba-readiness__fill { background: var(--ba-deadline-close); }

/* --- Cartes et listes denses -------------------------------------------------- */
.ba-card {
  background: var(--ba-surface);
  border: 1px solid var(--ba-border);
  border-radius: var(--ba-radius);
  box-shadow: var(--ba-shadow);
  padding: 12px 14px;
}
.ba-card--clickable { cursor: pointer; }
.ba-card--clickable:hover { border-color: var(--ba-primary); }
.ba-card--clickable:focus-visible {
  outline: 2px solid var(--ba-primary);
  outline-offset: 2px;
}

/* --- Kanban (#19) --------------------------------------------------------------- */
.ba-kanban {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: minmax(230px, 1fr);
  gap: var(--ba-gap-lg);
  overflow-x: auto;
  align-items: start;
  padding-bottom: var(--ba-gap-lg);
}
.ba-kanban__column {
  background: var(--ba-bg);
  border: 1px solid var(--ba-border);
  border-radius: var(--ba-radius);
  padding: var(--ba-gap);
  min-height: 120px;
}
.ba-kanban__title {
  display: flex;
  justify-content: space-between;
  font-size: var(--ba-font-size-dense);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ba-text-muted);
  padding: 4px 6px 8px;
}
.ba-kanban__cards { display: flex; flex-direction: column; gap: var(--ba-gap); min-height: 60px; }
.ba-kanban .ba-card { font-size: var(--ba-font-size-dense); }
.ba-kanban__ghost { opacity: 0.4; }

/* --- États vides (toujours une action, #52) --------------------------------------- */
.ba-empty {
  text-align: center;
  color: var(--ba-text-muted);
  padding: 32px 16px;
  border: 1px dashed var(--ba-border);
  border-radius: var(--ba-radius);
}

/* --- Chargements LLM : étapes nommées, jamais de spinner muet ------------------------ */
.ba-llm-progress { display: flex; align-items: center; gap: var(--ba-gap); color: var(--ba-text-muted); }
.ba-llm-progress__dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--ba-accent);
  animation: ba-pulse 1.2s ease-in-out infinite;
}
@keyframes ba-pulse { 0%, 100% { opacity: 0.3; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .ba-llm-progress__dot { animation: none; }
  .ba-readiness__fill { transition: none; }
}

/* ============================================================================
   REFONTE #76 — composants transverses. Tout écran les consomme tels quels.
   ============================================================================ */

/* --- Reset minimal du shell -------------------------------------------------- */
.ba-shell *, .ba-shell *::before, .ba-shell *::after { box-sizing: border-box; }

/* --- Boutons ------------------------------------------------------------------ */
.ba-btn {
  font: inherit;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid var(--ba-border);
  background: var(--ba-surface);
  color: var(--ba-text);
  border-radius: var(--ba-radius);
  padding: 7px 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}
.ba-btn:hover { border-color: var(--ba-primary); }
.ba-btn--primary { background: var(--ba-primary); border-color: var(--ba-primary); color: #fff; }
.ba-btn--primary:hover { border-color: var(--ba-primary); filter: brightness(1.15); }
.ba-btn--accent { background: var(--ba-accent); border-color: var(--ba-accent); color: #fff; }
.ba-btn--accent:hover { border-color: var(--ba-accent); filter: brightness(1.1); }
.ba-btn--danger { border-color: var(--ba-nogo); color: var(--ba-nogo); background: var(--ba-surface); }
.ba-btn--ghost { border-color: transparent; background: none; }
.ba-btn:disabled { opacity: 0.5; cursor: default; pointer-events: none; }
.ba-btn:focus-visible { outline: 2px solid var(--ba-primary); outline-offset: 2px; }
.ba-btn .ba-icon { flex-shrink: 0; }

/* --- Formulaires ---------------------------------------------------------------- */
.ba-input, .ba-select, .ba-textarea {
  font: inherit;
  width: 100%;
  border: 1px solid var(--ba-border);
  border-radius: var(--ba-radius);
  padding: 7px 10px;
  background: var(--ba-surface);
  color: var(--ba-text);
}
.ba-textarea { min-height: 80px; resize: vertical; }
.ba-input:focus-visible, .ba-select:focus-visible, .ba-textarea:focus-visible {
  outline: 2px solid var(--ba-primary);
  outline-offset: 1px;
}
.ba-label {
  display: block;
  font-size: var(--ba-font-size-xs);
  color: var(--ba-text-muted);
  margin: 10px 0 3px;
}
.ba-field { display: block; }
.ba-checkbox { display: inline-flex; gap: 6px; align-items: center; font-size: var(--ba-font-size-dense); }
.ba-checkbox input { width: auto; }

/* --- Icônes (sprite maison, #76) ------------------------------------------------- */
.ba-icon {
  width: 18px;
  height: 18px;
  vertical-align: -3.5px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ba-icon--lg { width: 22px; height: 22px; }

/* --- Shell : sidebar + topbar ------------------------------------------------------ */
.ba-shell {
  display: grid;
  grid-template-columns: var(--ba-sidebar-width) minmax(0, 1fr);
  min-height: 100vh;
  font-family: var(--ba-font);
  font-size: var(--ba-font-size);
  background: var(--ba-bg);
  color: var(--ba-text);
  margin: 0;
}
.ba-sidebar {
  background: var(--ba-sidebar-bg);
  color: var(--ba-sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 14px 10px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.ba-sidebar__brand {
  font-family: var(--ba-font-display);
  font-weight: 700;
  font-size: var(--ba-font-size-md);
  color: var(--ba-sidebar-active);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 18px;
  text-decoration: none;
}
.ba-sidebar__nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.ba-sidebar__link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--ba-radius);
  color: var(--ba-sidebar-text);
  text-decoration: none;
  font-size: var(--ba-font-size-dense);
  font-weight: 600;
}
.ba-sidebar__link:hover { color: var(--ba-sidebar-active); background: var(--ba-sidebar-active-bg); }
.ba-sidebar__link[aria-current="page"] {
  color: var(--ba-sidebar-active);
  background: var(--ba-sidebar-active-bg);
  box-shadow: inset 2.5px 0 0 var(--ba-accent);
}
.ba-sidebar__link:focus-visible { outline: 2px solid var(--ba-sidebar-active); outline-offset: -2px; }
.ba-sidebar__foot {
  border-top: 1px solid rgba(255, 255, 255, 0.12);
  padding-top: 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.ba-sidebar__foot .ba-sidebar__link { color: var(--ba-sidebar-muted); }
.ba-sidebar__foot .ba-sidebar__link:hover { color: var(--ba-sidebar-active); }
.ba-main { display: flex; flex-direction: column; min-width: 0; }
.ba-topbar {
  display: flex;
  align-items: center;
  gap: var(--ba-gap-lg);
  flex-wrap: wrap;
  padding: 12px 24px;
  border-bottom: 1px solid var(--ba-border);
  background: var(--ba-surface);
  position: sticky;
  top: 0;
  z-index: 20;
}
.ba-topbar__title {
  font-family: var(--ba-font-display);
  font-weight: 700;
  font-size: var(--ba-font-size-lg);
  margin: 0;
}
.ba-topbar__actions { display: flex; gap: var(--ba-gap); align-items: center; flex-wrap: wrap; margin-left: auto; }
.ba-content { padding: 20px 24px; flex: 1; }

/* Responsive : rail d'icônes sous 1024px, la marque et les libellés se replient */
@media (max-width: 1024px) {
  .ba-shell { grid-template-columns: 60px minmax(0, 1fr); }
  .ba-sidebar { padding: 12px 6px; align-items: center; }
  .ba-sidebar__brand span, .ba-sidebar__link span { display: none; }
  .ba-sidebar__link { justify-content: center; padding: 10px; }
}
@media (max-width: 640px) {
  .ba-shell { grid-template-columns: 1fr; }
  .ba-sidebar {
    position: sticky;
    height: auto;
    flex-direction: row;
    align-items: center;
    z-index: 30;
  }
  .ba-sidebar__nav { flex-direction: row; overflow-x: auto; }
  .ba-sidebar__foot { border-top: none; flex-direction: row; padding-top: 0; }
}

/* --- Onglets -------------------------------------------------------------------------- */
.ba-tabs {
  display: flex;
  gap: 2px;
  border-bottom: 1px solid var(--ba-border);
  overflow-x: auto;
}
.ba-tab {
  font: inherit;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  padding: 8px 14px;
  cursor: pointer;
  color: var(--ba-text-muted);
  white-space: nowrap;
}
.ba-tab[aria-selected="true"] { color: var(--ba-text); border-bottom-color: var(--ba-primary); font-weight: 600; }
.ba-tab:focus-visible { outline: 2px solid var(--ba-primary); outline-offset: -2px; }

/* --- Drawer (panneau latéral du shell) --------------------------------------------------- */
.ba-drawer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(680px, 92vw);
  background: var(--ba-surface);
  border-left: 1px solid var(--ba-border);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.12);
  padding: 20px 24px;
  overflow-y: auto;
  z-index: 50;
}
.ba-drawer[hidden] { display: none; }
.ba-drawer__close { position: absolute; top: 14px; right: 14px; }

/* --- Modale -------------------------------------------------------------------------------- */
.ba-modal {
  position: fixed;
  inset: 0;
  z-index: 60;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--ba-gap-lg);
}
.ba-modal[hidden] { display: none; }
.ba-modal__backdrop { position: absolute; inset: 0; background: rgba(10, 20, 30, 0.45); }
.ba-modal__box {
  position: relative;
  background: var(--ba-surface);
  border: 1px solid var(--ba-border);
  border-radius: var(--ba-radius);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  width: min(520px, 94vw);
  max-height: 88vh;
  overflow-y: auto;
  padding: 20px 24px;
}

/* --- Toasts ------------------------------------------------------------------------------------ */
.ba-toasts {
  position: fixed;
  bottom: 16px;
  right: 16px;
  z-index: 80;
  display: flex;
  flex-direction: column;
  gap: var(--ba-gap);
  max-width: min(420px, 90vw);
}
.ba-toast {
  background: var(--ba-primary);
  color: #fff;
  border-radius: var(--ba-radius);
  padding: 10px 14px;
  font-size: var(--ba-font-size-dense);
  box-shadow: var(--ba-shadow);
  display: flex;
  gap: 8px;
  align-items: baseline;
}
.ba-toast--success { background: var(--ba-go); }
.ba-toast--error { background: var(--ba-nogo); }

/* --- Tables & listes descriptives (migrés du proto #55) ------------------------------------------- */
.ba-table { width: 100%; border-collapse: collapse; font-size: var(--ba-font-size-dense); }
.ba-table th, .ba-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--ba-border); }
.ba-table th { color: var(--ba-text-muted); font-weight: 600; }
.ba-table .num { text-align: right; font-family: var(--ba-font-mono); font-variant-numeric: tabular-nums; font-size: var(--ba-font-size-xs); }
.ba-kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; font-size: var(--ba-font-size-dense); }
.ba-kv dt { color: var(--ba-text-muted); }
.ba-kv dd { margin: 0; font-variant-numeric: tabular-nums; }
.ba-risk {
  border-left: 3px solid var(--ba-etudier);
  padding: 6px 10px;
  background: var(--ba-bg);
  border-radius: 0 var(--ba-radius) var(--ba-radius) 0;
  font-size: var(--ba-font-size-dense);
}
.ba-risk + .ba-risk { margin-top: var(--ba-gap); }
.ba-risk--high { border-left-color: var(--ba-nogo); }
.ba-check { list-style: none; display: flex; flex-direction: column; gap: 6px; font-size: var(--ba-font-size-dense); padding: 0; margin: 0; }
.ba-check li { display: flex; gap: var(--ba-gap); align-items: baseline; }
.ba-check .ok { color: var(--ba-go); font-weight: 700; }
.ba-check .ko { color: var(--ba-nogo); font-weight: 700; }

/* Données chiffrées : échéances, montants, codes CPV, références */
.ba-data { font-family: var(--ba-font-mono); font-variant-numeric: tabular-nums; font-size: var(--ba-font-size-xs); }

/* --- Le verdict-tampon (signature de la refonte) ---------------------------------------------------- */
.ba-stamp {
  display: inline-block;
  transform: rotate(-2deg);
  border: 2px solid var(--ba-etudier);
  box-shadow: inset 0 0 0 1.5px var(--ba-surface), inset 0 0 0 2.5px var(--ba-etudier);
  color: var(--ba-etudier);
  font-family: var(--ba-font-display);
  font-weight: 700;
  font-size: var(--ba-font-size-md);
  letter-spacing: 0.12em;
  text-transform: uppercase;
  padding: 5px 14px;
  border-radius: 3px;
  opacity: 0.92;
  white-space: nowrap;
}
.ba-stamp--go { border-color: var(--ba-go); color: var(--ba-go); box-shadow: inset 0 0 0 1.5px var(--ba-surface), inset 0 0 0 2.5px var(--ba-go); }
.ba-stamp--nogo { border-color: var(--ba-nogo); color: var(--ba-nogo); box-shadow: inset 0 0 0 1.5px var(--ba-surface), inset 0 0 0 2.5px var(--ba-nogo); }
/* Mini-sceau rond pour les cartes (radar, kanban) */
.ba-seal {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  border: 1.5px solid var(--ba-etudier);
  box-shadow: inset 0 0 0 1px var(--ba-surface), inset 0 0 0 1.75px var(--ba-etudier);
  color: var(--ba-etudier);
  font-weight: 700;
  font-size: var(--ba-font-size-xs);
  font-family: var(--ba-font-display);
  transform: rotate(-4deg);
}
.ba-seal--go { border-color: var(--ba-go); color: var(--ba-go); box-shadow: inset 0 0 0 1px var(--ba-surface), inset 0 0 0 1.75px var(--ba-go); }
.ba-seal--nogo { border-color: var(--ba-nogo); color: var(--ba-nogo); box-shadow: inset 0 0 0 1px var(--ba-surface), inset 0 0 0 1.75px var(--ba-nogo); }

/* --- htmx : indicateurs et transitions ------------------------------------------------------------------ */
.htmx-indicator { display: none; }
.htmx-request .htmx-indicator, .htmx-request.htmx-indicator { display: flex; }
.ba-swap-fade.htmx-settling { animation: ba-fade-in 120ms ease-out; }
@keyframes ba-fade-in { from { opacity: 0.35; } to { opacity: 1; } }

/* Le balayage radar : orchestration signature au refresh de la liste (#78) */
.ba-sweep { position: relative; overflow: hidden; }
.ba-sweep.htmx-settling::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 30%;
  background: linear-gradient(90deg, transparent, rgba(14, 124, 102, 0.10), transparent);
  animation: ba-sweep-pass 500ms ease-out;
  pointer-events: none;
}
@keyframes ba-sweep-pass { from { left: -35%; } to { left: 105%; } }
@media (prefers-reduced-motion: reduce) {
  .ba-swap-fade.htmx-settling { animation: none; }
  .ba-sweep.htmx-settling::after { animation: none; content: none; }
}

/* Titres : la display porte la personnalité */
.ba-h1 { font-family: var(--ba-font-display); font-weight: 700; font-size: var(--ba-font-size-lg); margin: 0; }
.ba-h2 { font-family: var(--ba-font-display); font-weight: 600; font-size: var(--ba-font-size-md); margin: 0 0 var(--ba-gap); }
.ba-h3 {
  font-size: var(--ba-font-size-dense);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ba-text-muted);
  margin: 0 0 var(--ba-gap);
  font-weight: 600;
}

/* Utilitaires d'urgence d'échéance (macro deadline) */
.u-deadline-soon { color: var(--ba-deadline-soon); }
.u-deadline-close { color: var(--ba-deadline-close); font-weight: 700; }
