/* Audits Énergies — Design tokens */

@import url('https://fonts.googleapis.com/css2?family=General+Sans:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Warm paper light mode */
  --paper: #F5F2EC;
  --paper-2: #EDEAE3;
  --paper-3: #E4E0D7;
  --ink: #0E1010;
  --ink-2: #2B2D2E;
  --ink-3: #54575A;
  --ink-4: #8A8D90;
  --ink-5: #B8BAB9;
  --line: rgba(14,16,16,0.08);
  --line-2: rgba(14,16,16,0.14);
  --hairline: rgba(14,16,16,0.06);

  /* Signal palette — single accent family */
  --signal: #3FE07C;      /* electric lime-green */
  --signal-deep: #0F7A3D;
  --signal-tint: rgba(63,224,124,0.12);
  --signal-soft: rgba(63,224,124,0.22);

  --copper: #C66A2B;      /* warnings only */
  --copper-tint: rgba(198,106,43,0.12);
  --amber: #E8B341;
  --plasma: #6B4CFF;      /* rare, for AI/copilot */
  --plasma-tint: rgba(107,76,255,0.10);
  --rouge: #D94646;       /* errors only */
  --rouge-tint: rgba(217,70,70,0.10);
  --rouge-soft: rgba(217,70,70,0.25);
  --amber-tint: rgba(232,179,65,0.12);

  --shadow-1: 0 1px 0 rgba(14,16,16,0.04), 0 1px 2px rgba(14,16,16,0.04);
  --shadow-2: 0 1px 0 rgba(14,16,16,0.04), 0 8px 24px -8px rgba(14,16,16,0.12);
  --shadow-3: 0 12px 40px -10px rgba(14,16,16,0.18);

  --r-1: 4px;
  --r-2: 8px;
  --r-3: 12px;

  --font-sans: "General Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  /* Grid */
  --gap: 16px;
}

:root[data-theme="dark"] {
  --paper: #0B0D0E;
  --paper-2: #111315;
  --paper-3: #16191B;
  --ink: #F1EFEA;
  --ink-2: #D8D5CE;
  --ink-3: #A3A6A9;
  --ink-4: #6E7174;
  --ink-5: #484B4E;
  --line: rgba(255,255,255,0.06);
  --line-2: rgba(255,255,255,0.12);
  --hairline: rgba(255,255,255,0.04);

  --signal: #9FF29A;
  --signal-deep: #3FE07C;
  --signal-tint: rgba(159,242,154,0.10);
  --signal-soft: rgba(159,242,154,0.18);

  /* O5 — Dark mode : recolore les autres tons pour contraste WCAG AA */
  --copper: #E89855;
  --copper-tint: rgba(232,152,85,0.14);
  --amber: #F0C04E;
  --amber-tint: rgba(240,192,78,0.14);
  --plasma: #9485FF;
  --plasma-tint: rgba(148,133,255,0.14);
  --rouge: #FF7575;
  --rouge-tint: rgba(255,117,117,0.14);
  --rouge-soft: rgba(255,117,117,0.30);

  --shadow-1: 0 1px 0 rgba(0,0,0,0.5), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-2: 0 1px 0 rgba(0,0,0,0.5), 0 8px 24px -8px rgba(0,0,0,0.5);
  --shadow-3: 0 12px 40px -10px rgba(0,0,0,0.6);
}

* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  font-family: var(--font-sans);
  background: var(--paper);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-feature-settings: "ss01", "ss02", "cv11";
}
::selection { background: var(--signal-soft); color: var(--ink); }

.mono { font-family: var(--font-mono); font-feature-settings: "zero", "ss02"; letter-spacing: -0.02em; }
.num  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; font-feature-settings: "zero", "tnum"; }

button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
button:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
  border-radius: 3px;
}

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--line-2); border-radius: 10px; border: 2px solid var(--paper); }
::-webkit-scrollbar-thumb:hover { background: var(--ink-4); }

/* The signature breath dot for the co-pilot */
@keyframes breathe {
  0%, 100% { opacity: 0.35; transform: scale(1); }
  50% { opacity: 1; transform: scale(1.25); }
}
@keyframes dot-pulse {
  0% { box-shadow: 0 0 0 0 var(--signal-soft); }
  70% { box-shadow: 0 0 0 10px rgba(63,224,124,0); }
  100% { box-shadow: 0 0 0 0 rgba(63,224,124,0); }
}
@keyframes count-up {
  from { opacity: 0; transform: translateY(4px); filter: blur(3px); }
  to   { opacity: 1; transform: translateY(0);   filter: blur(0); }
}
@keyframes scanline {
  0% { transform: translateY(-100%); }
  100% { transform: translateY(200%); }
}
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}
@keyframes draw-line {
  from { stroke-dashoffset: 1000; }
  to   { stroke-dashoffset: 0; }
}
@keyframes fade-up {
  from { opacity: 0; transform: translateY(6px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes tick {
  0%,100% { transform: scaleY(1); }
  50%     { transform: scaleY(1.35); }
}

.fade-up { animation: fade-up 280ms cubic-bezier(.2,.8,.2,1) both; }
.count-up { animation: count-up 360ms cubic-bezier(.2,.8,.2,1) both; }

/* O4 — Micro-interactions CSS pour remplacer Framer Motion */
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes slideInRight { from { opacity: 0; transform: translateX(30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideInLeft { from { opacity: 0; transform: translateX(-30px); } to { opacity: 1; transform: translateX(0); } }
@keyframes slideInUp { from { opacity: 0; transform: translateY(20px); } to { opacity: 1; transform: translateY(0); } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.9); } to { opacity: 1; transform: scale(1); } }
@keyframes pulseHighlight { 0%,100% { box-shadow: 0 0 0 0 var(--signal-tint); } 50% { box-shadow: 0 0 0 8px var(--signal-tint); } }
@keyframes wiggle { 0%,100% { transform: rotate(0); } 25% { transform: rotate(-3deg); } 75% { transform: rotate(3deg); } }

.anim-fade-in { animation: fadeIn 250ms ease-out both; }
.anim-slide-right { animation: slideInRight 320ms cubic-bezier(.2,.8,.2,1) both; }
.anim-slide-left { animation: slideInLeft 320ms cubic-bezier(.2,.8,.2,1) both; }
.anim-slide-up { animation: slideInUp 320ms cubic-bezier(.2,.8,.2,1) both; }
.anim-scale-in { animation: scaleIn 240ms cubic-bezier(.2,.8,.2,1) both; }
.anim-pulse { animation: pulseHighlight 2s ease-in-out infinite; }
.anim-wiggle:hover { animation: wiggle 400ms ease-in-out; }

/* Stagger delays pour listes */
.anim-stagger > * { animation: slideInUp 320ms cubic-bezier(.2,.8,.2,1) both; }
.anim-stagger > *:nth-child(1) { animation-delay: 0ms; }
.anim-stagger > *:nth-child(2) { animation-delay: 40ms; }
.anim-stagger > *:nth-child(3) { animation-delay: 80ms; }
.anim-stagger > *:nth-child(4) { animation-delay: 120ms; }
.anim-stagger > *:nth-child(5) { animation-delay: 160ms; }
.anim-stagger > *:nth-child(6) { animation-delay: 200ms; }
.anim-stagger > *:nth-child(7) { animation-delay: 240ms; }
.anim-stagger > *:nth-child(8) { animation-delay: 280ms; }

/* Hover micro-interactions */
button:not(:disabled), [role="button"]:not(:disabled), a {
  transition: transform 120ms ease-out, box-shadow 120ms ease-out, background 150ms;
}
button:not(:disabled):active, [role="button"]:not(:disabled):active {
  transform: scale(0.97);
}

/* Cards lift on hover */
.card-hover {
  transition: transform 200ms cubic-bezier(.2,.8,.2,1), box-shadow 200ms;
}
.card-hover:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-2);
}

/* Skeleton shimmer (déjà utilisé par empty-states) — garde la même keyframe */
@keyframes shimmer {
  0% { background-position: -200% 0; }
  100% { background-position: 200% 0; }
}

/* Reduce motion accessibility (WCAG) */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

/* N6 — Accessibility WCAG 2.1 AA améliorations */
/* Skip-link pour navigation clavier */
.skip-link {
  position: absolute; top: -40px; left: 0;
  background: var(--ink); color: var(--paper);
  padding: 8px 16px; z-index: 100000;
  text-decoration: none; font-weight: 600;
  border-radius: 0 0 5px 0;
}
.skip-link:focus {
  top: 0;
  outline: 3px solid var(--signal);
}

/* Visible focus indicator (au-delà du défaut navigateur) */
:focus-visible {
  outline: 2px solid var(--signal) !important;
  outline-offset: 2px !important;
}

/* Sr-only : texte caché visuellement mais lu par les lecteurs d'écran */
.sr-only {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  padding: 0 !important;
  margin: -1px !important;
  overflow: hidden !important;
  clip: rect(0, 0, 0, 0) !important;
  white-space: nowrap !important;
  border: 0 !important;
}

/* High contrast preference */
@media (prefers-contrast: more) {
  :root {
    --line: rgba(14,16,16,0.25);
    --line-2: rgba(14,16,16,0.45);
    --ink-4: #54575A; /* augmente contraste pour texte secondaire */
  }
  :root[data-theme="dark"] {
    --line: rgba(255,255,255,0.25);
    --line-2: rgba(255,255,255,0.45);
    --ink-4: #C0C2C5;
  }
}

/* Force underline sur tous les links (sauf nav buttons) */
a:not(.btn):not([role="button"]) {
  text-decoration: underline;
  text-underline-offset: 2px;
}

/* Touchable size : min 44x44px sur mobile (WCAG 2.5.5) */
@media (pointer: coarse) {
  button, [role="button"], a, input, select, textarea {
    min-height: 44px;
  }
}

/* Grainy paper texture overlay, super subtle */
.paper-grain::before {
  content: "";
  position: fixed; inset: 0;
  pointer-events: none;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='160' height='160'><filter id='n'><feTurbulence baseFrequency='0.9' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0.035 0'/></filter><rect width='100%25' height='100%25' filter='url(%23n)'/></svg>");
  mix-blend-mode: multiply;
  opacity: 0.6;
  z-index: 9999;
}
:root[data-theme="dark"] .paper-grain::before { mix-blend-mode: screen; opacity: 0.35; }

/* ──────────────────────────────────────────────────────────────────── */
/*  COMPATIBILITÉ LEGACY → DESIGN-V1                                     */
/*  Alias pour composants portés depuis audits-energies.html             */
/*  (audit-page, gov-page, webhooks-page, misc-pages, final-pages)       */
/*  Règle n°0 : l'UI design-v1 reste la source visuelle de vérité.      */
/*  Ces alias garantissent la cohérence sans modifier 5 fichiers JSX.   */
/* ──────────────────────────────────────────────────────────────────── */
:root {
  /* Variables de l'ancienne V → tokens design-v1 */
  --bg1: var(--paper);
  --bg2: var(--paper-2);
  --bg3: var(--paper-3);
  --border: var(--line);
  --fg: var(--ink);
  --t1: var(--ink-2);
  --t2: var(--ink-3);
  --t3: var(--ink-4);
  --muted: var(--ink-4);
  --accent: var(--signal);
  --accent-deep: var(--signal-deep);
  --accent-tint: var(--signal-tint);
}

/* Inputs & selects */
.fi, .fs {
  padding: 7px 10px;
  font-size: 12px;
  border: 1px solid var(--line-2);
  border-radius: 5px;
  background: var(--paper-2);
  color: var(--ink);
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
  transition: border-color 120ms, box-shadow 120ms;
}
.fi:focus, .fs:focus {
  outline: none;
  border-color: var(--signal);
  box-shadow: 0 0 0 3px var(--signal-tint);
}
.fs {
  appearance: none;
  -webkit-appearance: none;
  background-image:
    linear-gradient(45deg, transparent 50%, var(--ink-4) 50%),
    linear-gradient(135deg, var(--ink-4) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 9px) 50%;
  background-size: 5px 5px;
  background-repeat: no-repeat;
  padding-right: 26px;
}
.fi::placeholder { color: var(--ink-4); }

/* Labels */
.lbl {
  display: block;
  font-size: 10px;
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  margin-bottom: 4px;
}

/* Buttons — mapping sur le même langage visuel que <Btn> */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 5px;
  border: 1px solid var(--line-2);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: background 120ms, border-color 120ms, box-shadow 120ms;
  font-family: inherit;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--paper-2); border-color: var(--line-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn.b-primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.btn.b-primary:hover { background: var(--ink-2); border-color: var(--ink-2); }

.btn.b-ghost {
  background: transparent;
  border-color: var(--line-2);
  color: var(--ink-2);
}
.btn.b-ghost:hover { background: var(--paper-2); }

.btn.b-amber {
  background: var(--copper-tint);
  color: var(--copper);
  border-color: var(--copper);
}
.btn.b-amber:hover { background: rgba(198,106,43,0.22); }

.btn.b-signal {
  background: var(--signal);
  color: #0B1F12;
  border-color: var(--signal-deep);
  font-weight: 600;
}
.btn.b-signal:hover { background: var(--signal-deep); color: var(--paper); }

.btn.b-rouge {
  background: var(--paper);
  color: var(--rouge);
  border-color: var(--rouge);
}
.btn.b-rouge:hover { background: var(--rouge-tint); }

/* Cards & pills génériques */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  overflow: hidden;
}
.pill, .tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  background: var(--paper-2);
  border: 1px solid var(--line-2);
  border-radius: 999px;
  color: var(--ink-3);
  white-space: nowrap;
}

/* Fieldsets legacy */
fieldset.fieldset, .fieldset {
  border: 1px solid var(--line);
  border-radius: var(--r-2);
  padding: 10px 12px;
  background: var(--paper-2);
}
.fieldset > legend {
  font-size: 10px;
  color: var(--ink-4);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
  padding: 0 6px;
}
