/* ==========================================================================
   crypt — feuille de style unique.

   Organisation :
     1. Tokens (couleurs, typo, espaces, rayons, ombres)
     2. Base & typographie
     3. Chrome applicatif (topbar, layout, footer)
     4. Formulaires & boutons
     5. Cartes, tableaux, métriques
     6. Graphes & légendes
     7. Composants divers (chips, alertes, spinners, éditeur)
     8. Login
     9. Utilitaires & motion

   Les couleurs de données (--series-*, --good/--critical/--warning) viennent
   d'une palette validée pour le daltonisme et les contrastes : ne pas les
   retoucher sans revalider. Le reste (surfaces, marque, ombres) est libre.
   ========================================================================== */

/* ---------- 1. Tokens ---------- */

:root {
  color-scheme: light;

  /* Surfaces & encre */
  --plane: #f7f7f5;
  --plane-deep: #efefeb;
  --surface: #fcfcfb;
  --surface-2: #f4f4f1;
  --surface-inset: #f0efec;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --muted: #898781;
  --grid: #e1e0d9;
  --axis: #c3c2b7;
  --border: rgba(11, 11, 11, 0.1);
  --border-strong: rgba(11, 11, 11, 0.16);

  /* Marque & états */
  --accent: #2a78d6;
  --accent-hover: #256abf;
  --accent-soft: rgba(42, 120, 214, 0.1);
  --accent-ink: #1c5cab;
  --brand-from: #2a78d6;
  --brand-to: #4a3aa7;
  --good: #0ca30c;
  --good-ink: #006300;
  --critical: #d03b3b;
  --warning: #fab219;
  --serious: #ec835a;

  /* Séries de données (palette validée — light) */
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --series-3: #1baf7a;
  --series-4: #eda100;
  --series-5: #e87ba4;
  --series-6: #008300;
  --series-7: #4a3aa7;
  --series-8: #e34948;

  /* Typographie */
  --font-sans: "Inter", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, "JetBrains Mono", Menlo, Consolas, monospace;

  /* Rayons */
  --r-xs: 6px;
  --r-sm: 8px;
  --r-md: 11px;
  --r-lg: 16px;
  --r-xl: 22px;
  --r-full: 999px;

  /* Élévation — douce, jamais dure */
  --shadow-1: 0 1px 2px rgba(11, 11, 11, 0.04), 0 1px 3px rgba(11, 11, 11, 0.03);
  --shadow-2: 0 2px 4px rgba(11, 11, 11, 0.04), 0 8px 20px -8px rgba(11, 11, 11, 0.1);
  --shadow-3: 0 4px 8px rgba(11, 11, 11, 0.05), 0 24px 48px -16px rgba(11, 11, 11, 0.16);
  --shadow-accent: 0 1px 2px rgba(28, 92, 171, 0.24), 0 8px 18px -8px rgba(28, 92, 171, 0.5);
  --ring: 0 0 0 3px rgba(42, 120, 214, 0.28);
  /* Ombre d'indice de défilement horizontal (cf. `.table-wrap`). */
  --scroll-shade: rgba(11, 11, 11, 0.16);

  --header-h: 3.75rem;
  /* Padding interne des cartes : `.card-foot` s'en sert pour ressortir en
     pleine largeur, les deux doivent rester synchronisés. */
  --card-pad-y: 1.15rem;
  --card-pad-x: 1.25rem;
}

/* Thème sombre : même palette de séries, pas restéppée arbitrairement. */
@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) {
    color-scheme: dark;

    --plane: #0d0d0d;
    --plane-deep: #080808;
    --surface: #1a1a19;
    --surface-2: #212120;
    --surface-inset: #131312;
    --text: #ffffff;
    --text-secondary: #c3c2b7;
    --muted: #898781;
    --grid: #2c2c2a;
    --axis: #383835;
    --border: rgba(255, 255, 255, 0.1);
    --border-strong: rgba(255, 255, 255, 0.16);

    --accent: #3987e5;
    --accent-hover: #5598e7;
    --accent-soft: rgba(57, 135, 229, 0.16);
    --accent-ink: #86b6ef;
    --brand-from: #3987e5;
    --brand-to: #9085e9;
    --good: #0ca30c;
    --good-ink: #0ca30c;
    --critical: #d03b3b;

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;
    --series-5: #d55181;
    --series-6: #008300;
    --series-7: #9085e9;
    --series-8: #e66767;

    --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.4), 0 8px 20px -8px rgba(0, 0, 0, 0.6);
    --shadow-3: 0 4px 8px rgba(0, 0, 0, 0.45), 0 24px 48px -16px rgba(0, 0, 0, 0.7);
    --shadow-accent: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 18px -8px rgba(57, 135, 229, 0.55);
    --ring: 0 0 0 3px rgba(57, 135, 229, 0.36);
    --scroll-shade: rgba(0, 0, 0, 0.55);
  }
}

/* Bascule manuelle : elle doit gagner dans les deux sens. */
:root[data-theme="dark"] {
  color-scheme: dark;

  --plane: #0d0d0d;
  --plane-deep: #080808;
  --surface: #1a1a19;
  --surface-2: #212120;
  --surface-inset: #131312;
  --text: #ffffff;
  --text-secondary: #c3c2b7;
  --muted: #898781;
  --grid: #2c2c2a;
  --axis: #383835;
  --border: rgba(255, 255, 255, 0.1);
  --border-strong: rgba(255, 255, 255, 0.16);

  --accent: #3987e5;
  --accent-hover: #5598e7;
  --accent-soft: rgba(57, 135, 229, 0.16);
  --accent-ink: #86b6ef;
  --brand-from: #3987e5;
  --brand-to: #9085e9;
  --good-ink: #0ca30c;

  --series-1: #3987e5;
  --series-2: #d95926;
  --series-3: #199e70;
  --series-4: #c98500;
  --series-5: #d55181;
  --series-6: #008300;
  --series-7: #9085e9;
  --series-8: #e66767;

  --shadow-1: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-2: 0 2px 4px rgba(0, 0, 0, 0.4), 0 8px 20px -8px rgba(0, 0, 0, 0.6);
  --shadow-3: 0 4px 8px rgba(0, 0, 0, 0.45), 0 24px 48px -16px rgba(0, 0, 0, 0.7);
  --shadow-accent: 0 1px 2px rgba(0, 0, 0, 0.4), 0 8px 18px -8px rgba(57, 135, 229, 0.55);
  --ring: 0 0 0 3px rgba(57, 135, 229, 0.36);
  --scroll-shade: rgba(0, 0, 0, 0.55);
}

/* ---------- 2. Base & typographie ---------- */

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  margin: 0;
  min-height: 100vh;
  background: var(--plane);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 15px;
  line-height: 1.55;
  font-feature-settings: "cv05" 1, "ss01" 1;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

/* Halo décoratif très discret derrière le contenu. */
body::before {
  content: "";
  position: fixed;
  inset: 0 0 auto;
  height: 26rem;
  pointer-events: none;
  z-index: 0;
  background:
    radial-gradient(60rem 22rem at 15% -8rem, var(--accent-soft), transparent 70%),
    radial-gradient(48rem 20rem at 90% -10rem, rgba(74, 58, 167, 0.09), transparent 70%);
}

a {
  color: var(--accent);
  text-decoration: none;
  text-underline-offset: 0.15em;
}

a:hover {
  text-decoration: underline;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--r-xs);
}

h1 {
  margin: 0;
  font-size: clamp(1.5rem, 1.2rem + 1vw, 1.9rem);
  line-height: 1.2;
  font-weight: 650;
  letter-spacing: -0.02em;
}

h2 {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-weight: 650;
}

h3 {
  margin: 0 0 0.4rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

code {
  font-family: var(--font-mono);
  font-size: 0.86em;
  padding: 0.08em 0.35em;
  border-radius: var(--r-xs);
  background: var(--surface-inset);
  border: 1px solid var(--border);
}

/* ---------- 3. Chrome applicatif ---------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  height: var(--header-h);
  padding: 0 clamp(1rem, 4vw, 2rem);
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface) 78%, transparent);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.6rem;
  color: var(--text);
  font-weight: 650;
  letter-spacing: 0.02em;
  flex: none;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 1.85rem;
  height: 1.85rem;
  border-radius: 0.6rem;
  background: linear-gradient(140deg, var(--brand-from), var(--brand-to));
  box-shadow: var(--shadow-accent);
  color: #fff;
  flex: none;
}

.brand-mark svg {
  width: 1.05rem;
  height: 1.05rem;
  display: block;
}

.brand-name {
  font-size: 1rem;
}

.brand-name b {
  font-weight: 650;
}

.topbar nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  margin-right: auto;
  overflow-x: auto;
  scrollbar-width: none;
}

.topbar nav::-webkit-scrollbar {
  display: none;
}

.topbar nav a {
  position: relative;
  padding: 0.42rem 0.8rem;
  border-radius: var(--r-full);
  color: var(--text-secondary);
  font-size: 0.9rem;
  font-weight: 500;
  white-space: nowrap;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.topbar nav a:hover {
  background: var(--surface-2);
  color: var(--text);
  text-decoration: none;
}

.topbar nav a.is-active {
  background: var(--accent-soft);
  color: var(--accent-ink);
  text-decoration: none;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex: none;
  margin-left: auto;
}

/* Mobile : la barre passe sur deux lignes. Sur une seule, la nav est le seul
   bloc compressible et ses libellés se faisaient tronquer en plein milieu. */
@media (max-width: 46rem) {
  .topbar {
    height: auto;
    flex-wrap: wrap;
    gap: 0.5rem;
    padding-top: 0.45rem;
    padding-bottom: 0.45rem;
  }

  /* `wrap` : à quatre entrées, la rangée dépasse la largeur d'un téléphone et
     la dernière (« Strategytator ») sortait de l'écran, hors de portée du
     doigt. Elles passent à la ligne plutôt que de déborder. */
  .topbar nav {
    order: 3;
    flex: 1 0 100%;
    margin-right: 0;
    gap: 0.25rem;
    overflow-x: visible;
    flex-wrap: wrap;
  }

  .topbar nav a {
    flex: 1 1 auto;
    text-align: center;
    padding: 0.35rem 0.5rem;
  }
}

/* Écrans vraiment étroits (< 304px) : le nom de marque et le libellé
   « Déconnexion » cèdent la place, leurs icônes suffisent. */
@media (max-width: 19rem) {
  .brand-name {
    display: none;
  }

  .topbar-actions .button.small span {
    display: none;
  }

  .topbar-actions .button.small {
    padding-inline: 0.5rem;
  }
}

main {
  position: relative;
  z-index: 1;
  max-width: 82rem;
  margin: 0 auto;
  padding: clamp(1.25rem, 3vw, 2.25rem) clamp(1rem, 4vw, 2rem) 4rem;
}

.page-head {
  margin-bottom: 1.5rem;
  max-width: 46rem;
}

.eyebrow {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  margin-bottom: 0.55rem;
  padding: 0.2rem 0.6rem 0.2rem 0.45rem;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface);
  color: var(--text-secondary);
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.07em;
  text-transform: uppercase;
}

.eyebrow::before {
  content: "";
  width: 0.4rem;
  height: 0.4rem;
  border-radius: 50%;
  background: linear-gradient(140deg, var(--brand-from), var(--brand-to));
}

.lead {
  margin: 0.5rem 0 0;
  color: var(--text-secondary);
  font-size: 0.95rem;
}

.site-foot {
  position: relative;
  z-index: 1;
  padding: 1.25rem clamp(1rem, 4vw, 2rem) 2rem;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.78rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem 1rem;
  justify-content: space-between;
  max-width: 82rem;
  margin: 0 auto;
}

/* Téléchargement de l'application Android */

.apk-cta {
  display: flex;
  align-items: center;
  gap: 0.9rem;
  flex-wrap: wrap;
  margin-bottom: 1.5rem;
  padding: 0.85rem 1.1rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-1);
}

.apk-cta-mark {
  display: grid;
  place-items: center;
  width: 2.4rem;
  height: 2.4rem;
  flex: none;
  border-radius: var(--r-sm);
  background: linear-gradient(140deg, var(--brand-from), var(--brand-to));
  color: #fff;
}

.apk-cta-mark svg {
  width: 1.25rem;
  height: 1.25rem;
}

/* `min-width: 0` : sans ça, le texte long empêche le conteneur flex de
   rétrécir et le bouton déborde sur les écrans étroits. */
.apk-cta-text {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1 1 14rem;
  min-width: 0;
}

.apk-cta-text b {
  font-size: 0.92rem;
  font-weight: 600;
}

.apk-cta-text span {
  color: var(--muted);
  font-size: 0.78rem;
}

.foot-apk {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--text-secondary);
}

.foot-apk svg {
  width: 0.95rem;
  height: 0.95rem;
}

/* Layout */

.split {
  display: grid;
  grid-template-columns: 21.5rem minmax(0, 1fr);
  gap: 1.25rem;
  align-items: start;
}

/* Page Stratégies : la liste et l'éditeur se partagent la largeur. */
.split.editor {
  grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr);
}

@media (max-width: 64rem) {
  .split,
  .split.editor {
    grid-template-columns: minmax(0, 1fr);
  }
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
}

/* Classe doublée : `.card` (section 5) déclare aussi `position` et gagnerait à
   spécificité égale, ce qui décalait le panneau de la valeur de `top` sans
   jamais le coller. */
.sticky-panel.sticky-panel {
  position: sticky;
  top: calc(var(--header-h) + 1rem);
}

@media (max-width: 64rem) {
  .sticky-panel.sticky-panel {
    position: static;
  }
}

/* ---------- 4. Formulaires & boutons ---------- */

label {
  display: block;
  font-size: 0.74rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
  margin-bottom: 0.35rem;
  overflow-wrap: break-word;
}

input,
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.7rem;
  min-height: 2.3rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background-color 0.15s ease;
}

input:hover,
select:hover,
textarea:hover {
  border-color: var(--axis);
}

input:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: var(--accent);
  background: var(--surface);
  box-shadow: var(--ring);
}

input[readonly] {
  color: var(--text-secondary);
  cursor: not-allowed;
}

select {
  appearance: none;
  padding-right: 2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16' fill='none' stroke='%23898781' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M4 6.5 8 10.5l4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.55rem center;
  background-size: 1rem;
  cursor: pointer;
}

input[type="checkbox"] {
  width: 1.05rem;
  height: 1.05rem;
  min-height: 0;
  padding: 0;
  accent-color: var(--accent);
  cursor: pointer;
}

::placeholder {
  color: var(--muted);
}

.field {
  flex: 1 1 8rem;
  min-width: 7rem;
}

/* Sous 384px, deux champs côte à côte laissent moins de place que ne demande
   « Capital initial (€) » : le libellé en capitales se casse sur deux lignes et
   désaligne la rangée. Un champ par ligne, plutôt. */
@media (max-width: 24rem) {
  .row > .field {
    flex-basis: 100%;
  }
}

/* iOS Safari zoome sur tout champ dont le texte fait moins de 16px : sur
   mobile on relève la taille pour que la mise au point ne déplace pas la page. */
@media (max-width: 46rem) {
  input,
  select {
    font-size: 16px;
  }
}

.hint {
  margin-top: 0.35rem;
  color: var(--muted);
  font-size: 0.78rem;
}

.fieldset-label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
  font-size: 0.74rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.fieldset-label::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

button,
.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.45rem;
  padding: 0.55rem 1.05rem;
  min-height: 2.3rem;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: linear-gradient(180deg, var(--accent), var(--accent-hover));
  color: #fff;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 550;
  line-height: 1;
  cursor: pointer;
  box-shadow: var(--shadow-accent);
  transition: transform 0.12s ease, box-shadow 0.15s ease, background-color 0.15s ease,
    border-color 0.15s ease, color 0.15s ease;
}

button:hover,
.button:hover {
  text-decoration: none;
  transform: translateY(-1px);
}

button:active,
.button:active {
  transform: translateY(0);
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

button svg,
.button svg {
  width: 0.95rem;
  height: 0.95rem;
  flex: none;
}

button.secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-1);
}

button.secondary:hover {
  background: var(--surface-2);
  border-color: var(--axis);
}

button.ghost {
  background: transparent;
  color: var(--text-secondary);
  box-shadow: none;
}

button.ghost:hover {
  background: var(--surface-2);
  color: var(--text);
}

button.danger {
  background: transparent;
  color: var(--critical);
  border-color: color-mix(in srgb, var(--critical) 40%, transparent);
  box-shadow: none;
}

button.danger:hover {
  background: color-mix(in srgb, var(--critical) 10%, transparent);
  border-color: var(--critical);
}

button.small,
.button.small {
  padding: 0.32rem 0.7rem;
  min-height: 1.9rem;
  font-size: 0.8rem;
}

.icon-btn {
  width: 2.2rem;
  height: 2.2rem;
  min-height: 0;
  padding: 0;
  border-radius: var(--r-sm);
  background: transparent;
  border-color: transparent;
  color: var(--text-secondary);
  box-shadow: none;
}

.icon-btn:hover {
  background: var(--surface-2);
  color: var(--text);
  transform: none;
}

/* Au doigt, une cible de 2.2rem (35px) est trop petite : on l'élargit sans
   toucher au rendu à la souris. */
@media (pointer: coarse) {
  .icon-btn {
    width: 2.6rem;
    height: 2.6rem;
  }

  input[type="checkbox"] {
    width: 1.25rem;
    height: 1.25rem;
  }
}

.icon-btn svg {
  width: 1.05rem;
  height: 1.05rem;
}

.icon-btn.danger {
  color: var(--muted);
  border-color: transparent;
}

.icon-btn.danger:hover {
  color: var(--critical);
  background: color-mix(in srgb, var(--critical) 12%, transparent);
}

/* Bascule de thème : on affiche l'icône du mode vers lequel on basculerait. */
.theme-toggle .icon-sun {
  display: none;
}

.theme-toggle .icon-moon {
  display: block;
}

@media (prefers-color-scheme: dark) {
  :root:where(:not([data-theme="light"])) .theme-toggle .icon-sun {
    display: block;
  }
  :root:where(:not([data-theme="light"])) .theme-toggle .icon-moon {
    display: none;
  }
}

:root[data-theme="dark"] .theme-toggle .icon-sun {
  display: block;
}

:root[data-theme="dark"] .theme-toggle .icon-moon {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-sun {
  display: none;
}

:root[data-theme="light"] .theme-toggle .icon-moon {
  display: block;
}

/* ---------- 5. Cartes, tableaux, métriques ---------- */

.card {
  position: relative;
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-1);
  padding: var(--card-pad-y) var(--card-pad-x);
  margin-bottom: 1.25rem;
}

.card:last-child {
  margin-bottom: 0;
}

.card.flush {
  padding: 0;
  overflow: hidden;
}

@media (max-width: 46rem) {
  .card {
    --card-pad-y: 1rem;
    --card-pad-x: 0.9rem;
    margin-bottom: 1rem;
  }
}

.card-head {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin: -0.15rem 0 1rem;
}

.card-head h2,
.card-head h3 {
  margin: 0;
}

.card-head .card-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.card-title {
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.card-sub {
  color: var(--muted);
  font-size: 0.8rem;
}

.card-foot {
  margin: 1rem calc(var(--card-pad-x) * -1) calc(var(--card-pad-y) * -1);
  padding: 0.75rem var(--card-pad-x);
  border-top: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 0 0 var(--r-lg) var(--r-lg);
  color: var(--muted);
  font-size: 0.8rem;
}

.card-foot a {
  color: var(--accent);
}

/* Tableaux */

/* Les tableaux débordent forcément sur mobile (12 colonnes). Les dégradés en
   `background-attachment: local` servent d'indice : une ombre apparaît du côté
   où il reste du contenu à faire défiler, et disparaît en bout de course. */
.table-wrap {
  overflow-x: auto;
  overscroll-behavior-x: contain;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background:
    linear-gradient(to right, var(--surface) 30%, transparent) left / 2.5rem 100% no-repeat local,
    linear-gradient(to left, var(--surface) 30%, transparent) right / 2.5rem 100% no-repeat local,
    radial-gradient(farthest-side at 0 50%, var(--scroll-shade), transparent) left / 0.75rem 100% no-repeat scroll,
    radial-gradient(farthest-side at 100% 50%, var(--scroll-shade), transparent) right / 0.75rem 100% no-repeat scroll,
    var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th,
td {
  padding: 0.6rem 0.8rem;
  text-align: right;
  border-bottom: 1px solid var(--grid);
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

th:first-child,
td:first-child,
th.text,
td.text {
  text-align: left;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 1;
  background: var(--surface-2);
  color: var(--muted);
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 650;
  border-bottom: 1px solid var(--border);
}

thead th a {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  color: inherit;
  padding: 0.1rem 0.25rem;
  margin: -0.1rem -0.25rem;
  border-radius: var(--r-xs);
}

thead th a:hover {
  background: var(--accent-soft);
  color: var(--accent-ink);
  text-decoration: none;
}

thead th a.is-sorted {
  color: var(--text);
}

td.num,
th.num {
  font-variant-numeric: tabular-nums;
}

tbody tr {
  transition: background-color 0.12s ease;
}

tbody tr:hover {
  background: var(--accent-soft);
}

tbody td:first-child {
  font-weight: 500;
}

.positive {
  color: var(--good-ink);
}

.negative {
  color: var(--critical);
}

.row-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.35rem;
}

/* Mobile : on resserre les cellules pour faire tenir plus de colonnes dans le
   viewport avant d'avoir à faire défiler. */
@media (max-width: 46rem) {
  table {
    font-size: 0.82rem;
  }

  th,
  td {
    padding: 0.5rem 0.55rem;
  }
}

/* Métriques */

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(9.5rem, 1fr));
  gap: 0.6rem;
  margin: 0;
}

.metric {
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  padding: 0.7rem 0.85rem;
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.metric:hover {
  border-color: var(--border-strong);
}

.metric dt {
  margin: 0 0 0.2rem;
  font-size: 0.7rem;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}

.metric dd {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 620;
  letter-spacing: -0.02em;
  line-height: 1.15;
}

/* La tuile héros : le chiffre que la page raconte — toujours sur toute la
   largeur, son chiffre est trop grand pour une demi-colonne de téléphone. */
.metric.hero {
  grid-column: 1 / -1;
  background: linear-gradient(150deg, var(--accent-soft), transparent 65%), var(--surface);
  border-color: color-mix(in srgb, var(--accent) 28%, var(--border));
}

.metric.hero dd {
  font-size: clamp(1.9rem, 1.4rem + 1.6vw, 2.6rem);
  font-weight: 650;
}

@media (max-width: 30rem) {
  .metrics {
    grid-template-columns: repeat(auto-fit, minmax(8rem, 1fr));
  }
}

.metric-note {
  display: block;
  margin-top: 0.2rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: var(--muted);
  letter-spacing: 0;
}

/* ---------- 6. Graphes & légendes ---------- */

.chart {
  height: clamp(15rem, 12rem + 18vw, 20rem);
  width: 100%;
}

.chart.tall {
  height: clamp(18rem, 14rem + 22vw, 25rem);
}

/* Lecteur temporel (injecté par charts.js sous chaque graphe) : lecture,
   curseur, durée de simulation et bornes de la période. */
.chart-player {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  margin-top: 0.7rem;
  padding: 0.6rem 0.7rem;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface-2);
}

.player-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem 0.7rem;
}

.player-btn {
  flex: none;
  width: 2.1rem;
  height: 2.1rem;
  min-height: 0;
  padding: 0;
  border-radius: var(--r-full);
}

.player-btn svg {
  width: 1.05rem;
  height: 1.05rem;
}

.player-btn.ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border-strong);
}

.player-btn.ghost:hover {
  background: var(--surface);
  color: var(--text);
}

.chart-player input[type="range"] {
  flex: 1 1 8rem;
  width: auto;
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  accent-color: var(--accent);
  cursor: pointer;
}

.chart-player input[type="range"]:focus {
  box-shadow: none;
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.player-bound {
  accent-color: var(--muted);
}

.player-time,
.player-span {
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
  color: var(--text-secondary);
  white-space: nowrap;
}

.player-time {
  min-width: 8.5rem;
  text-align: right;
  font-weight: 600;
  color: var(--text);
}

.player-label {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
}

.player-duration {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  margin: 0;
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.player-duration input {
  width: 3.6rem;
  min-height: 2rem;
  padding: 0.25rem 0.4rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

/* Sous 480px, curseur et bornes prennent toute la largeur : côte à côte, les
   deux bornes deviendraient trop courtes pour viser une date. */
@media (max-width: 480px) {
  .player-bounds {
    flex-direction: column;
    align-items: stretch;
  }

  .chart-player input[type="range"] {
    flex-basis: 100%;
  }

  .player-time {
    text-align: left;
  }
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
  margin-top: 0.75rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
  font-size: 0.82rem;
  color: var(--text-secondary);
}

.legend-item {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
}

.swatch {
  /* Hors d'un conteneur flex (une cellule de tableau, par exemple) un span
     reste en ligne et ignore ses dimensions : la pastille disparaîtrait. */
  display: inline-block;
  vertical-align: middle;
  width: 0.7rem;
  height: 0.7rem;
  border-radius: 3px;
  flex: none;
  box-shadow: 0 0 0 2px var(--surface);
}

.swatch.line {
  width: 0.9rem;
  height: 0.2rem;
  border-radius: var(--r-full);
}

/* Infobulle des graphes (injectée par charts.js). */
.chart-tip {
  position: absolute;
  z-index: 20;
  min-width: 8rem;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  box-shadow: var(--shadow-3);
  font-size: 0.8rem;
  line-height: 1.45;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.1s ease;
}

.chart-tip.is-visible {
  opacity: 1;
}

.chart-tip .tip-time {
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.3rem;
}

.chart-tip .tip-row {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  white-space: nowrap;
}

.chart-tip .tip-row .tip-value {
  margin-left: auto;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
}

/* ---------- 7. Composants divers ---------- */

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: var(--r-full);
  background: var(--surface-2);
  font-size: 0.72rem;
  font-weight: 550;
  letter-spacing: 0.02em;
  color: var(--text-secondary);
  text-transform: uppercase;
}

.chip.is-builtin {
  border-color: color-mix(in srgb, var(--accent) 35%, transparent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.alert {
  display: flex;
  gap: 0.65rem;
  border: 1px solid color-mix(in srgb, var(--critical) 35%, transparent);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--critical) 8%, var(--surface));
  padding: 0.75rem 0.9rem;
  margin-bottom: 1rem;
  color: var(--text);
  font-size: 0.875rem;
}

.alert::before {
  content: "!";
  display: grid;
  place-items: center;
  width: 1.15rem;
  height: 1.15rem;
  flex: none;
  margin-top: 0.1rem;
  border-radius: 50%;
  background: var(--critical);
  color: #fff;
  font-size: 0.75rem;
  font-weight: 700;
  line-height: 1;
}

.alert.ok {
  border-color: color-mix(in srgb, var(--good) 35%, transparent);
  background: color-mix(in srgb, var(--good) 8%, var(--surface));
}

/* Note neutre : ni erreur, ni succès (ex. troncature d'une sélection). */
.alert.info {
  border-color: color-mix(in srgb, var(--accent) 32%, transparent);
  background: color-mix(in srgb, var(--accent) 7%, var(--surface));
}

.alert.info::before {
  content: "i";
  background: var(--accent);
  font-family: var(--font-mono);
}

.alert.ok::before {
  content: "✓";
  background: var(--good);
  font-size: 0.7rem;
}

.alert-body {
  min-width: 0;
}

.alert pre {
  margin: 0.5rem 0 0;
  max-height: 14rem;
  overflow: auto;
  padding: 0.5rem 0.6rem;
  border-radius: var(--r-xs);
  background: var(--surface-inset);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--text-secondary);
  white-space: pre-wrap;
}

.empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  padding: 2.5rem 1rem;
  text-align: center;
  font-size: 0.9rem;
}

.empty svg {
  width: 1.75rem;
  height: 1.75rem;
  opacity: 0.6;
}

.card.empty {
  border-style: dashed;
  box-shadow: none;
  background: color-mix(in srgb, var(--surface) 60%, transparent);
}

.muted {
  color: var(--muted);
  font-size: 0.82rem;
}

/* Page Strategytator : ligne mise en avant (stratégie étudiée dans un
   tableau de comparaison) et journal d'itérations de l'optimisation. */
tr.is-current td {
  background: var(--accent-soft);
  font-weight: 600;
}

.iteration-log {
  display: flex;
  flex-direction: column;
  gap: 1.1rem;
  margin: 0;
  padding: 0 0 0 1.1rem;
}

.iteration-log li {
  border-left: 2px solid var(--border);
  padding: 0.15rem 0 0.15rem 1rem;
}

.iteration-log li::marker {
  color: var(--muted);
  font-weight: 600;
}

.iteration-title {
  font-weight: 650;
  font-size: 1rem;
}

.iteration-result {
  margin: 0.4rem 0 0;
  padding-left: 0.75rem;
  border-left: 2px solid color-mix(in srgb, var(--accent) 45%, transparent);
  color: var(--text-secondary);
}

/* Indicateurs de chargement */

.spinner {
  display: none;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.82rem;
}

.htmx-request .spinner,
.spinner.htmx-request {
  display: inline-flex;
}

.spinner::before {
  content: "";
  width: 0.85rem;
  height: 0.85rem;
  border-radius: 50%;
  border: 2px solid var(--axis);
  border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* Progression d'un run : chargement des données puis analyse. */

.progress {
  height: 8px;
  border-radius: var(--r-full);
  background: var(--surface-inset);
  border: 1px solid var(--border);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, var(--brand-from), var(--brand-to));
  transition: width 0.35s ease;
  position: relative;
  overflow: hidden;
}

/* Reflet mobile : signale que le travail continue même quand le pourcentage
   stagne (téléchargement d'une longue plage). */
.progress-fill::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  background: linear-gradient(
    90deg,
    transparent,
    color-mix(in srgb, #fff 45%, transparent),
    transparent
  );
  animation: sheen 1.4s ease-in-out infinite;
}

@keyframes sheen {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(300%);
  }
}

.progress-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem 1.1rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.progress-steps li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.progress-steps li::before {
  content: "";
  width: 0.6rem;
  height: 0.6rem;
  border-radius: 50%;
  border: 2px solid var(--axis);
}

.progress-steps li.is-active {
  color: var(--text);
  font-weight: 600;
}

.progress-steps li.is-active::before {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.progress-steps li.is-done::before {
  border-color: var(--good);
  background: var(--good);
}

/* Barre de progression globale HTMX. */
.load-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  z-index: 60;
  background: transparent;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}

.load-bar.is-active {
  opacity: 1;
}

.load-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: 35%;
  background: linear-gradient(90deg, transparent, var(--accent), var(--brand-to), transparent);
  animation: slide 1.1s ease-in-out infinite;
}

@keyframes slide {
  0% {
    transform: translateX(-100%);
  }
  100% {
    transform: translateX(320%);
  }
}

/* Liste de stratégies */

.strategy-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.strategy-list li {
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  background: var(--surface-2);
  transition: border-color 0.15s ease;
}

.strategy-list li:hover {
  border-color: var(--border-strong);
}

.strategy-list li.empty {
  border-style: dashed;
  background: transparent;
  padding: 1.1rem 0.85rem;
}

.strategy-list .name {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 600;
  font-size: 0.92rem;
}

.strategy-list .desc {
  color: var(--text-secondary);
  font-size: 0.85rem;
  margin-top: 0.15rem;
}

.strategy-list .params {
  margin-top: 0.3rem;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--muted);
}

.file-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

/* Comparatif multi-stratégies (panneau du formulaire de backtest) */

.multi-strategies {
  border-top: 1px solid var(--border);
  padding-top: 0.9rem;
}

.multi-strategies > summary {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 550;
  list-style: none;
}

.multi-strategies > summary::-webkit-details-marker {
  display: none;
}

.multi-strategies > summary::after {
  content: "";
  margin-left: auto;
  width: 0.5rem;
  height: 0.5rem;
  border-right: 1.5px solid var(--muted);
  border-bottom: 1.5px solid var(--muted);
  transform: rotate(45deg) translate(-0.1rem, -0.1rem);
  transition: transform 0.15s ease;
}

.multi-strategies[open] > summary::after {
  transform: rotate(-135deg) translate(-0.1rem, -0.1rem);
}

.multi-strategies .fieldset-label {
  margin-top: 0.9rem;
}

.multi-strategies .fieldset-label:first-child {
  margin-top: 0;
}

/* La bibliothèque compte plusieurs dizaines de stratégies : la liste défile
   dans le panneau, sinon le bouton de lancement finit hors de l'écran. */
.check-groups {
  max-height: 20rem;
  overflow-y: auto;
  margin-top: 0.6rem;
  padding-right: 0.4rem;
}

.check-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.check {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.2rem 0;
  font-size: 0.86rem;
  cursor: pointer;
}

.check > span {
  font-family: var(--font-mono);
  font-size: 0.8rem;
}

.check:hover > span {
  color: var(--text);
}

tr.is-reference {
  color: var(--text-secondary);
}

.file-row .muted svg {
  display: block;
  width: 1.05rem;
  height: 1.05rem;
  color: var(--muted);
}

.file-row .name {
  font-family: var(--font-mono);
  font-size: 0.85rem;
  font-weight: 500;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-row .row-actions {
  margin-left: auto;
}

/* Éditeur de code */

textarea {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  line-height: 1.6;
  min-height: 26rem;
  resize: vertical;
  white-space: pre;
  tab-size: 4;
  background: var(--surface-inset);
}

.editor-wrap {
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  overflow: hidden;
  background: var(--surface-inset);
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.editor-wrap:focus-within {
  border-color: var(--accent);
  box-shadow: var(--ring);
}

.editor-bar {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  font-family: var(--font-mono);
  font-size: 0.74rem;
  color: var(--muted);
}

.editor-bar .dots {
  display: flex;
  gap: 0.25rem;
  margin-right: 0.35rem;
}

.editor-bar .dots i {
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: var(--axis);
}

.editor-wrap textarea {
  border: none;
  border-radius: 0;
  box-shadow: none;
  background: transparent;
}

.editor-wrap textarea:focus {
  box-shadow: none;
  background: transparent;
}

/* Mobile : l'éditeur occupe moins de hauteur, et 16px évitent le zoom iOS
   à la mise au point (cf. la règle équivalente sur `input`/`select`). */
@media (max-width: 46rem) {
  textarea {
    min-height: 18rem;
    font-size: 16px;
    line-height: 1.5;
  }
}

/* ---------- 8. Login ---------- */

.login-body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  background: var(--plane-deep);
  overflow: hidden;
}

/* Même pseudo-élément que `body::before` : on réinitialise sa hauteur. */
.login-body::before {
  content: "";
  position: fixed;
  inset: -20%;
  height: auto;
  z-index: 0;
  background:
    radial-gradient(38rem 30rem at 22% 18%, color-mix(in srgb, var(--brand-from) 40%, transparent), transparent 65%),
    radial-gradient(34rem 28rem at 80% 78%, color-mix(in srgb, var(--brand-to) 38%, transparent), transparent 65%),
    radial-gradient(28rem 24rem at 68% 12%, color-mix(in srgb, var(--series-3) 22%, transparent), transparent 70%);
  filter: blur(10px);
  animation: drift 26s ease-in-out infinite alternate;
}

@keyframes drift {
  to {
    transform: translate3d(2%, -2%, 0) scale(1.06);
  }
}

.login-main {
  position: relative;
  z-index: 1;
  width: 100%;
  padding: 1.5rem;
}

.login-card {
  width: min(23rem, 100%);
  margin: 0 auto;
  padding: 1.75rem;
  border-radius: var(--r-xl);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  backdrop-filter: saturate(160%) blur(18px);
  -webkit-backdrop-filter: saturate(160%) blur(18px);
  box-shadow: var(--shadow-3);
  border-color: var(--border-strong);
}

.login-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  font-weight: 650;
  font-size: 1.05rem;
}

.login-card h1 {
  font-size: 1.25rem;
  margin-bottom: 0.2rem;
}

.login-card .lead {
  margin: 0.25rem 0 1.25rem;
  font-size: 0.875rem;
}

.login-card .field {
  margin-bottom: 0.9rem;
  flex: none;
}

.login-card button {
  width: 100%;
  margin-top: 0.35rem;
}

.login-foot {
  margin: 1.1rem 0 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.74rem;
}

/* ---------- 9. Utilitaires & motion ---------- */

.flow > * + * {
  margin-top: 1.25rem;
}

.mt-0 {
  margin-top: 0;
}

.mb-0 {
  margin-bottom: 0;
}

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

.fade-in {
  animation: fade-in 0.28s ease both;
}

@keyframes fade-in {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
}

/* Le contenu remplacé par HTMX arrive en douceur. */
.htmx-added .card,
#backtest-result > *,
#compare-chart > * {
  animation: fade-in 0.28s ease both;
}

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

/* Scrollbars discrètes (WebKit). */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--axis);
  border: 3px solid transparent;
  background-clip: content-box;
  border-radius: var(--r-full);
}

::-webkit-scrollbar-thumb:hover {
  background: var(--muted);
  background-clip: content-box;
}

@media print {
  .topbar,
  .site-foot,
  .load-bar,
  button {
    display: none !important;
  }
}
