/*
 * Fondation CSS site - tokens + briques composables + composants partagés.
 *
 * Chargement : fonts.css → common.css → design.css (+ report.css / rgaa.css / report_pdf.css).
 *
 * Briques : .row .surface .pill .btn .meter .swatch .info-tip .stack .eyebrow .caption
 * Partagés : .readable-table* .app-dialog*
 * Composition : class="pill pill--success" / "surface surface--accent" / "meter meter--stack"
 */

/* ==========================================================================
   Tokens (:root) - ex-tokens.css
   ========================================================================== */

:root {
  /* Brand Kapt */
  --primary: #5d56f1;
  --primary-dark: #4f48da;
  --primary-soft: #8a85f5;
  --primary-soft-bg: #eeedfe;
  --primary-soft-bg-hover: #e2e0fd;
  --primary-soft-text: #3d38a8;
  --primary-soft-border: #c5c2f5;
  --secondary: #13e9c3;
  --secondary-dark: #13be9f;
  --text: #1a1a2e;

  /* Shell */
  --bg: #f4f6f8;
  --surface: #fff;
  --surface-accent: #fafbfc;
  --muted: #6b7280;
  --border: #dee2e6;
  --table-row-stripe: #f6f7f9;
  --link: var(--primary);
  --danger: #c0392b;
  --danger-dark: #a32f23;

  /* Layout */
  --radius: 12px;
  --radius-pill: 999px;
  --radius-lg: 12px;
  --radius-card: 0.75rem;
  --space-2xs: 0.25rem;
  --space-xs: 0.35rem;
  --space-sm: 0.5rem;
  --space-md: 0.75rem;
  --space-lg: 1rem;
  --space-gap-row: 0.35rem 0.65rem;
  --shadow: 0 1px 3px rgb(0 0 0 / 8%);
  --shadow-sm: 0 4px 16px rgb(15 23 42 / 8%);
  --shadow-md: 0 8px 30px rgb(0 0 0 / 15%);
  --shadow-primary: 0 8px 24px rgb(93 86 241 / 25%);
  --track-bg: #e2e8f0;

  /* Typography */
  --font-body: "Dm Sans", system-ui, -apple-system, sans-serif;
  --font-title: "Space Grotesk Bold", system-ui, sans-serif;
  --text-micro: 0.65rem;

  /* Motion */
  --ease-boing: cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes submenu-jelly {
  0% {
    transform: translateY(-10px) scale(0.92, 1.1);
    opacity: 0;
  }

  30% {
    transform: translateY(4px) scale(1.06, 0.94);
    opacity: 1;
  }

  55% {
    transform: translateY(-2px) scale(0.98, 1.02);
  }

  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@keyframes dialog-jelly {
  0% {
    transform: scale(0.94, 1.04) translateY(8px);
    opacity: 0;
  }

  30% {
    transform: scale(1.02, 0.98) translateY(-1px);
    opacity: 1;
  }

  55% {
    transform: scale(0.995, 1.005) translateY(0.5px);
  }

  100% {
    transform: scale(1) translateY(0);
    opacity: 1;
  }
}

/* Popover ouvrant vers le haut (ex. info score-global). */
@keyframes tooltip-jelly-up {
  0% {
    transform: translateY(8px) scale(0.92, 1.1);
    opacity: 0;
  }

  30% {
    transform: translateY(-3px) scale(1.06, 0.94);
    opacity: 1;
  }

  55% {
    transform: translateY(2px) scale(0.98, 1.02);
  }

  100% {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

@media (prefers-reduced-motion: no-preference) {
  body > header nav details[open] > div {
    animation: submenu-jelly 0.5s var(--ease-boing) forwards;
  }

  dialog.app-dialog[open]:not(.is-closing) {
    animation: dialog-jelly 0.5s var(--ease-boing) forwards;
  }

  .campaign-card,
  .report-score-card,
  .report-score-global,
  .rgaa-evidence-card,
  article.campaign-card {
    transition:
    transform 0.38s var(--ease-boing),
    box-shadow 0.38s ease;
  }

  .campaign-card:hover,
  .report-score-card:hover,
  .report-score-global:hover,
  .rgaa-evidence-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 10px 28px var(--report-section-shadow, rgb(0 0 0 / 10%));
  }
}

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

/* ==========================================================================
   Atoms - row
   ========================================================================== */

.row {
  display: flex;
  align-items: center;
  gap: var(--space-sm);
  min-width: 0;
}

.row--between {
  justify-content: space-between;
}

.row--center {
  justify-content: center;
}

.row--baseline {
  align-items: baseline;
}

.row--start {
  align-items: flex-start;
}

.row--wrap {
  flex-wrap: wrap;
}

.row--column {
  flex-direction: column;
  align-items: stretch;
}

/* ==========================================================================
   Atoms - surface
   ========================================================================== */

.surface {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-sizing: border-box;
}

.surface--accent {
  background: var(--surface-accent);
}

.surface--raised {
  box-shadow: var(--shadow-sm);
}

.surface--pad {
  padding: var(--space-md) var(--space-lg);
}

.surface--dense {
  padding: var(--space-sm) var(--space-md);
}

/* ==========================================================================
   Atoms - info-tip (bouton i + tooltip)
   ========================================================================== */

.info-tip {
  position: relative;
  z-index: 2;
}

.info-tip__btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 1.5rem;
  height: 1.5rem;
  margin: 0;
  padding: 0;
  line-height: 1;
  border: 1px solid rgb(74 85 104 / 35%);
  border-radius: 50%;
  background: rgb(255 255 255 / 85%);
  color: var(--muted);
  cursor: help;
}

.info-tip__icon {
  display: block;
  font-size: 0.8rem;
  font-weight: 700;
  font-style: normal;
  line-height: 1;
}

.info-tip__tooltip {
  position: absolute;
  left: 0;
  top: calc(100% + 0.55rem);
  width: max-content;
  max-width: min(24rem, calc(100vw - 2rem));
  padding: 0.45rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 0.65rem;
  background: var(--surface);
  box-shadow: 0 8px 24px -8px rgb(15 23 42 / 18%);
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
  overflow: visible;
  transform: translateY(-6px) scale(0.96);
  transform-origin: top left;
  transition:
  opacity 0.2s ease,
  visibility 0.2s ease,
  transform 0.2s ease;
}

.info-tip--above .info-tip__tooltip {
  top: auto;
  bottom: calc(100% + 0.55rem);
  min-width: 12rem;
  max-width: min(20rem, calc(100vw - 2rem));
  padding: 0.55rem 0.7rem;
  transform: translateY(6px) scale(0.96);
  transform-origin: bottom left;
}

.info-tip__body {
  margin: 0;
  line-height: 1.45;
  color: var(--muted);
}

.info-tip__body math {
  display: inline-block;
  font-size: 0.9rem;
}

.info-tip:hover .info-tip__tooltip,
.info-tip:focus-within .info-tip__tooltip {
  opacity: 1;
  visibility: visible;
  pointer-events: auto;
  transform: none;
}

@media (prefers-reduced-motion: no-preference) {
  .info-tip:hover .info-tip__tooltip,
  .info-tip:focus-within .info-tip__tooltip {
    animation: submenu-jelly 0.5s var(--ease-boing) forwards;
  }

  .info-tip--above:hover .info-tip__tooltip,
  .info-tip--above:focus-within .info-tip__tooltip {
    animation: tooltip-jelly-up 0.5s var(--ease-boing) forwards;
  }
}

/* ==========================================================================
   Atoms - stack (listes verticales)
   ========================================================================== */

.stack {
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
  margin: 0;
  padding: 0;
  list-style: none;
}

.stack--tight {
  gap: var(--space-xs);
}

.stack--grid {
  display: grid;
  gap: var(--space-sm);
}

.stack--grid > li {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-md);
}

/* ==========================================================================
   Atoms - split-grid (hero + panneau latéral)
   ========================================================================== */

.split-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-lg);
  align-items: start;
}

@media (min-width: 720px) {
  .split-grid {
    grid-template-columns: minmax(0, 1fr) minmax(14rem, 0.95fr);
    gap: var(--space-lg);
  }
}

/* ==========================================================================
   Atoms - eyebrow / caption (labels muted)
   ========================================================================== */

.eyebrow {
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--muted);
}

.caption {
  margin: 0;
  font-size: 0.82rem;
  line-height: 1.35;
  color: var(--muted);
}

/* ==========================================================================
   Atoms - chart-legend
   ========================================================================== */

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-gap-row);
  margin: var(--space-md) 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.78rem;
  color: #475569;
}

.chart-legend .report-chart-legend-toggle {
  margin: 0;
  font-size: inherit;
}

.chart-legend .report-chart-legend-toggle i {
  width: 0.65rem;
  height: 0.65rem;
  border-radius: 0.1rem;
}

/* ==========================================================================
   Atoms - pill (+ alias status-pill pour migration)
   ========================================================================== */

.pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 0.2rem 0.55rem;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  box-sizing: border-box;
}

.pill--sm,
.status-pill.pill--sm {
  min-width: 1.25rem;
  padding: 0.05rem 0.35rem;
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.pill--label {
  padding: 0.12rem 0.5rem;
  font-size: 0.65rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-color: transparent;
}

.pill--muted {
  background: #f1f5f9;
  border-color: transparent;
  color: var(--muted);
}

.pill--warn {
  background: #fff7ed;
  border-color: transparent;
  color: #c2410c;
}

.pill--accent {
  background: #d4fbf4;
  border-color: #99f6e4;
  color: var(--text);
}

.pill--up,
.pill--positive {
  background: #d1fae5;
  border-color: transparent;
  color: #047857;
}

.pill--down,
.pill--negative {
  background: #fee2e2;
  border-color: transparent;
  color: #b91c1c;
}

.pill--flat {
  background: #e2e8f0;
  border-color: transparent;
  color: #475569;
}

.pill--success,
.pill--manual_success,
.status-pill--success,
.status-pill--manual_success {
  color: #1e6b3a;
  border-color: #b8e6c8;
  background: #e8f7ee;
}

.pill--failed,
.status-pill--failed {
  color: var(--danger);
  border-color: #f5c6cb;
  background: var(--surface);
}

.pill--paused,
.status-pill--paused {
  color: #b45309;
  border-color: #fcd34d;
  background: var(--surface);
}

.pill--running,
.status-pill--running {
  color: #0a6b58;
  border-color: rgb(19 233 195 / 45%);
  background: rgb(19 233 195 / 15%);
}

.pill--pending,
.status-pill--pending {
  color: var(--muted);
  border-color: var(--border);
  background: var(--surface);
}

.pill--warning,
.status-pill--warning {
  color: #b45309;
  border-color: #fcd34d;
  background: #fffbeb;
}

/* Modifiers RGAA (badges d’audit) */
.pill--review {
  background: #eef2ff;
  border-color: #c7d2fe;
  color: #3730a3;
}

.pill--partial {
  background: #fffbeb;
  border-color: #fcd34d;
  color: #b45309;
}

.pill--violations {
  background: #fff7ed;
  border-color: transparent;
  color: #c2410c;
}

.pill--incompletes {
  background: #f1f5f9;
  border-color: transparent;
  color: var(--muted);
}

/* ==========================================================================
   Atoms - btn
   ========================================================================== */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  margin: 0;
  padding: 0.3rem 0.75rem;
  font-size: 0.8125rem;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  text-decoration: none;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  box-sizing: border-box;
  transition:
  background-color 0.15s ease,
  border-color 0.15s ease,
  color 0.15s ease,
  box-shadow 0.15s ease;
}

.btn:hover {
  background: var(--primary-soft-bg);
  border-color: var(--primary-soft-border);
  color: var(--primary-soft-text);
  text-decoration: none;
}

.btn--primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #fff;
  box-shadow: var(--shadow-primary);
}

.btn--primary:hover {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
  color: #fff;
}

.btn--outline {
  background: transparent;
  border-color: var(--primary);
  color: var(--primary);
}

.btn--outline:hover {
  background: var(--primary-soft-bg);
  border-color: var(--primary-dark);
  color: var(--primary-dark);
}

.btn--ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--muted);
}

.btn--ghost:hover {
  background: var(--primary-soft-bg);
  border-color: var(--primary-soft-border);
  color: var(--primary-soft-text);
}

.btn--sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.72rem;
}

/* ==========================================================================
   Atoms - meter
   ========================================================================== */

.meter {
  min-width: 0;
}

.meter__track {
  position: relative;
  display: block;
  height: 0.4rem;
  border-radius: var(--radius-pill);
  background: var(--track-bg);
  overflow: hidden;
}

.meter__fill {
  display: block;
  height: 100%;
  width: calc(var(--meter-pct, 0) * 1%);
  border-radius: inherit;
  background: #818cf8;
}

.meter--absolute .meter__fill {
  position: absolute;
  inset: 0 auto 0 0;
}

.meter--stack {
  display: flex;
  height: 0.5rem;
  border-radius: var(--radius-pill);
  overflow: hidden;
  background: var(--track-bg);
}

.meter--stack .meter__segment {
  display: block;
  height: 100%;
  min-width: 0;
  width: calc(var(--meter-pct, 0) * 1%);
}

.meter--gap .meter__track {
  background: #f1f5f9;
}

.meter--gap .meter__axis {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  width: 1px;
  margin-left: -0.5px;
  background: #64748b;
  z-index: 1;
}

.meter--good .meter__fill {
  background: #34d399;
}

.meter--needs_improvement .meter__fill {
  background: #fbbf24;
}

.meter--poor .meter__fill {
  background: #f87171;
}

.meter--missing .meter__fill {
  width: 0;
  background: transparent;
}

.meter--observational .meter__fill {
  background: #94a3b8;
}

/* ==========================================================================
   Atoms - swatch (pastille couleur sans texte)
   ========================================================================== */

.swatch {
  display: inline-block;
  flex-shrink: 0;
  width: 0.75rem;
  height: 0.75rem;
  border-radius: var(--radius-pill);
}

.swatch--sm {
  width: 0.55rem;
  height: 0.55rem;
}

/* ==========================================================================
   Composant partagé - readable-table
   ========================================================================== */

section:has(.readable-table) {
  overflow-x: auto;
  max-width: 100%;
}

section:has(.readable-table-viewport) {
  overflow-x: visible;
}

.readable-table-viewport {
  overflow-x: auto;
  max-width: 100%;
}

.readable-table {
  font-size: 0.875rem;
  width: max-content;
  min-width: 100%;
}

.readable-table tbody td {
  max-width: 30rem;
  overflow: scroll;
}

.readable-table th,
.readable-table td {
  padding: 0.2rem 0.45rem;
  vertical-align: middle;
}

.readable-table select {
  width: auto;
  max-width: 14rem;
}

.readable-table td > a {
  margin-right: 0.65rem;
}

.readable-table td button {
  margin: 0;
  padding: 0.15rem 0.35rem;
  font-size: 0.8rem;
}

/* Cellule URL + lien externe (pages / live) */
.url-with-external-link {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  min-width: 0;
}

.url-with-external-link__text {
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ==========================================================================
   Composant partagé - app-dialog (+ shell dialog)
   ========================================================================== */

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  box-shadow: var(--shadow-md);
  width: min(1200px, 95%);
  max-width: 1200px;
  max-height: min(92vh, 920px);
  overflow: hidden;
}

dialog#rgaa-proofs-dialog {
  width: min(96vw, 1600px);
  max-width: min(96vw, 1600px);
  max-height: min(96vh, 1100px);
}

dialog.app-dialog {
  --dialog-duration: 0.2s;
  transition:
  overlay var(--dialog-duration) ease allow-discrete,
  display var(--dialog-duration) ease allow-discrete;
}

dialog.app-dialog:not([open]) {
  opacity: 0;
  transform: scale(0.96) translateY(8px);
}

@keyframes dialog-close {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }

  to {
    opacity: 0;
    transform: scale(0.96) translateY(8px);
  }
}

@keyframes dialog-backdrop-close {
  from {
    background: rgb(0 0 0 / 35%);
  }

  to {
    background: rgb(0 0 0 / 0%);
  }
}

dialog.app-dialog[open].is-closing {
  animation: dialog-close var(--dialog-duration) ease forwards;
  pointer-events: none;
}

dialog.app-dialog[open].is-closing::backdrop {
  animation: dialog-backdrop-close var(--dialog-duration) ease forwards;
}

dialog[open].app-dialog,
dialog[open] {
  display: flex;
  flex-direction: column;
  /* relative cassait le centrage modal → dialog collé en haut du document */
  position: fixed;
  inset: 0;
  margin: auto;
  height: fit-content;
}

dialog.app-dialog::backdrop {
  background: rgb(0 0 0 / 0%);
  transition:
  background-color var(--dialog-duration) ease,
  overlay var(--dialog-duration) ease allow-discrete,
  display var(--dialog-duration) ease allow-discrete;
}

dialog.app-dialog[open]:not(.is-closing)::backdrop {
  background: rgb(0 0 0 / 35%);
}

@starting-style {
  dialog.app-dialog[open]:not(.is-closing)::backdrop {
    background: rgb(0 0 0 / 0%);
  }
}

dialog::backdrop {
  background: rgb(0 0 0 / 35%);
}

.app-dialog__close {
  position: absolute;
  top: 0.625rem;
  right: 0.625rem;
  z-index: 2;
  margin: 0;
  padding: 0;
  border: 0;
  background: none;
}

.app-dialog__close button {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--muted);
  font-size: 1.35rem;
  line-height: 1;
  cursor: pointer;
}

.app-dialog__close button:hover {
  background: var(--primary-soft-bg-hover);
  border-color: var(--primary-soft-border);
  color: var(--primary-soft-text);
}

.app-dialog__scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 1.25rem 2.75rem 0.5rem 1.25rem;
}

.app-dialog__body {
  min-height: 2rem;
}

.app-dialog__footer {
  flex-shrink: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin: 0;
  padding: 0.75rem 1.25rem 1rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.app-dialog__footer-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  min-width: 0;
}

.app-dialog__footer-close {
  margin: 0;
  flex-shrink: 0;
}

.app-dialog__footer button {
  margin: 0;
}

.app-dialog__loading {
  margin: 0.5rem 0 1rem;
  color: var(--muted);
  font-size: 0.95rem;
}

dialog.is-loading .app-dialog__body {
  opacity: 0.72;
}

@media (prefers-reduced-motion: reduce) {
  dialog.app-dialog,
  dialog.app-dialog::backdrop {
    transition: none;
  }

  dialog.app-dialog[open]:not(.is-closing) {
    opacity: 1;
    transform: none;
  }

  dialog.app-dialog[open].is-closing,
  dialog.app-dialog[open].is-closing::backdrop {
    animation: none;
  }
}
