/* =========================================================
   Assistant décisionnel — Statistiques
   Direction : éditoriale. Serif pour les titres, beaucoup de blanc.
   ========================================================= */

:root {
  --bg:          #FBFAF8;
  --surface:     #FFFFFF;
  --surface-2:   #F4F2ED;
  --ink:         #161A18;
  --ink-2:       #3A403C;
  --muted:       #5C625E;
  --line:        #E5E2DC;
  --line-strong: #CFCBC3;

  --accent:      #2F5D50;
  --accent-deep: #234A40;
  --accent-weak: #EBF1EE;
  --accent-line: #C6D8D0;

  --warn:        #8A4B2A;
  --warn-weak:   #F7EFE8;

  --serif: "Source Serif 4", Georgia, "Times New Roman", serif;
  --sans:  "Source Sans 3", system-ui, -apple-system, "Segoe UI", sans-serif;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(22, 26, 24, .05);
  --shadow-md: 0 2px 4px rgba(22, 26, 24, .04), 0 8px 24px rgba(22, 26, 24, .05);

  --sidebar-w: 300px;
  --topbar-h: 60px;
}

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

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16.5px;
  line-height: 1.6;
  text-wrap: pretty;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--serif);
  font-weight: 600;
  line-height: 1.2;
  letter-spacing: -0.01em;
  margin: 0;
  color: var(--ink);
}

a { color: var(--accent-deep); text-decoration-thickness: 1px; text-underline-offset: 2px; }
a:hover { color: var(--accent); }

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

.skip-link {
  position: absolute;
  left: -9999px;
  top: 0;
  z-index: 100;
  background: var(--accent);
  color: #fff;
  padding: 10px 16px;
  border-radius: 0 0 var(--r-sm) 0;
}
.skip-link:focus { left: 0; color: #fff; }

/* ---------------------------------------------------------
   Barre supérieure (mobile / tablette)
   --------------------------------------------------------- */
.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 40;
  height: var(--topbar-h);
  align-items: center;
  gap: 12px;
  padding: 0 14px;
  background: rgba(251, 250, 248, .92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.topbar__brand {
  font-family: var(--serif);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--ink);
  text-decoration: none;
  margin-right: auto;
}

.topbar__burger {
  display: grid;
  gap: 4px;
  width: 44px;
  height: 44px;
  align-content: center;
  justify-items: center;
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
}
.topbar__burger span {
  display: block;
  width: 18px;
  height: 1.5px;
  background: var(--ink);
}

/* ---------------------------------------------------------
   Boutons
   --------------------------------------------------------- */
.btn {
  font-family: var(--sans);
  font-size: .92rem;
  font-weight: 600;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  cursor: pointer;
  padding: 9px 14px;
  min-height: 40px;
  background: var(--accent);
  color: #fff;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { background: var(--accent-deep); }

.btn--ghost {
  background: transparent;
  color: var(--accent-deep);
  border-color: var(--line-strong);
}
.btn--ghost:hover { background: var(--accent-weak); border-color: var(--accent-line); color: var(--accent-deep); }

.btn--link {
  background: none;
  border: none;
  color: var(--muted);
  padding: 4px 2px;
  min-height: 0;
  font-size: .8rem;
  font-weight: 400;
  text-decoration: underline;
  text-underline-offset: 2px;
}
.btn--link:hover { color: var(--ink); background: none; }

/* ---------------------------------------------------------
   Structure
   --------------------------------------------------------- */
.layout {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.scrim {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(22, 26, 24, .38);
  z-index: 45;
}

/* ---------------------------------------------------------
   Sidebar
   --------------------------------------------------------- */
.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  overflow-y: auto;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 26px;
  padding: 26px 20px 22px;
  background: var(--surface);
  border-right: 1px solid var(--line);
}

.sidebar__brand {
  display: flex;
  align-items: center;
  gap: 12px;
  text-decoration: none;
  color: var(--ink);
}
.sidebar__brand strong {
  display: block;
  font-family: var(--serif);
  font-size: 1.06rem;
  font-weight: 600;
  line-height: 1.25;
}
.sidebar__brand em {
  display: block;
  font-style: normal;
  font-size: .8rem;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}
.sidebar__mark {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  flex: none;
  border-radius: var(--r-sm);
  background: var(--accent);
  color: #fff;
  font-family: var(--serif);
  font-size: 1.25rem;
  line-height: 1;
}

.sidebar__legend {
  margin: 0 0 10px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

.sidebar__nav { flex: 1; }

.sidebar__foot {
  margin: 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  font-size: .76rem;
  color: var(--muted);
}

.toollist {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.toollist__link {
  display: block;
  padding: 9px 11px;
  border-radius: var(--r-sm);
  text-decoration: none;
  color: var(--ink-2);
  border-left: 2px solid transparent;
  transition: background .13s ease, color .13s ease;
}
.toollist__link:hover { background: var(--surface-2); color: var(--ink); }

.toollist__name {
  display: block;
  font-size: .95rem;
  font-weight: 600;
  line-height: 1.3;
}
.toollist__desc {
  display: block;
  font-size: .8rem;
  color: var(--muted);
  line-height: 1.35;
  margin-top: 1px;
}

.toollist__link[aria-current="page"] {
  background: var(--accent-weak);
  border-left-color: var(--accent);
  color: var(--accent-deep);
}
.toollist__link[aria-current="page"] .toollist__desc { color: var(--accent-deep); opacity: .8; }

/* Historique */
.history__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}
.history__list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.history__btn {
  width: 100%;
  text-align: left;
  background: none;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 7px 10px;
  cursor: pointer;
  font-family: var(--sans);
  color: var(--ink-2);
  transition: border-color .13s ease, background .13s ease;
}
.history__btn:hover { background: var(--surface-2); border-color: var(--line-strong); }
.history__tool {
  display: block;
  font-size: .84rem;
  font-weight: 600;
}
.history__vals {
  display: block;
  font-size: .78rem;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ---------------------------------------------------------
   Zone principale
   --------------------------------------------------------- */
.main {
  min-width: 0;
  padding: 52px 44px 96px;
}
.main:focus { outline: none; }

/* Accueil */
.home__intro { max-width: 62ch; margin-bottom: 40px; }
.home__title {
  font-size: clamp(2rem, 3.4vw, 2.7rem);
  letter-spacing: -0.02em;
  margin-bottom: 12px;
}
.home__lede {
  margin: 0;
  font-size: 1.12rem;
  color: var(--ink-2);
}

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(310px, 1fr));
  gap: 16px;
  max-width: 1180px;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 22px 22px 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  text-decoration: none;
  color: inherit;
  box-shadow: var(--shadow-sm);
  transition: border-color .15s ease, box-shadow .15s ease, transform .15s ease;
}
.card:hover {
  border-color: var(--accent-line);
  box-shadow: var(--shadow-md);
  transform: translateY(-1px);
  color: inherit;
}

.card__title {
  font-size: 1.16rem;
  letter-spacing: -0.01em;
}
.card__desc {
  margin: 0;
  font-size: .93rem;
  color: var(--muted);
  flex: 1;
}

/* Badges de prérequis */
.needs {
  list-style: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
}
.needs__label {
  font-size: .78rem;
  color: var(--muted);
  margin-right: 2px;
}
.needs__item {
  font-size: .78rem;
  line-height: 1;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  color: var(--ink-2);
  white-space: nowrap;
}
.needs__item--none {
  background: var(--accent-weak);
  border-color: var(--accent-line);
  color: var(--accent-deep);
}

/* En-tête d'outil */
.tool-head {
  max-width: 70ch;
  margin-bottom: 32px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--line);
}
.backlink {
  display: none;
  font-size: .88rem;
  color: var(--muted);
  text-decoration: none;
  margin-bottom: 14px;
}
.backlink:hover { color: var(--accent-deep); }

.tool-head__title {
  font-size: clamp(1.75rem, 2.9vw, 2.3rem);
  letter-spacing: -0.02em;
}
.tool-head__desc {
  margin: 10px 0 16px;
  font-size: 1.06rem;
  color: var(--ink-2);
}

/* ---------------------------------------------------------
   Grille saisie / résultats
   --------------------------------------------------------- */
.tool-grid {
  display: grid;
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
  gap: 30px;
  align-items: start;
  max-width: 1180px;
}

.tool-inputs {
  position: sticky;
  top: 32px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 24px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
}

.tool-results {
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-width: 0;
}

/* Le titre h3 hérité de chaque outil : discret, il double le h1 */
.tool-inputs h3, .tool-results h3 {
  font-size: 1.02rem;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .01em;
}
.tool-inputs h3 { margin-bottom: -4px; }

.fieldgroup { display: flex; flex-direction: column; gap: 16px; }
.fieldgroup__legend {
  font-family: var(--sans);
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
}

/* Champs */
.field { display: flex; flex-direction: column; gap: 5px; }
.field__label {
  font-size: .92rem;
  font-weight: 600;
  color: var(--ink-2);
}
.field__label .katex { font-size: 1em; }
.field__hint {
  margin: 0;
  font-size: .8rem;
  color: var(--muted);
}
.field__input,
.tool-inputs input[type="number"],
.tool-inputs input[type="text"],
.tool-inputs select {
  width: 100%;
  min-height: 44px;
  padding: 9px 12px;
  font-family: var(--sans);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  background: var(--bg);
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  transition: border-color .13s ease, box-shadow .13s ease, background .13s ease;
}
.field__input:hover { border-color: var(--muted); }
.field__input:focus,
.tool-inputs input:focus,
.tool-inputs select:focus {
  outline: none;
  background: var(--surface);
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-weak);
}

/* Options radio */
.options { display: flex; flex-direction: column; gap: 2px; }
.options__legend {
  font-size: .92rem;
  font-weight: 600;
  color: var(--ink-2);
  margin-bottom: 4px;
}
.opt {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
  padding: 4px 8px;
  border-radius: var(--r-sm);
  cursor: pointer;
  font-size: .95rem;
}
.opt:hover { background: var(--surface-2); }
.opt input[type="radio"] {
  width: 18px;
  height: 18px;
  accent-color: var(--accent);
  flex: none;
  margin: 0;
}
.opt:has(input:checked) { background: var(--accent-weak); color: var(--accent-deep); font-weight: 600; }

/* Curseur (InterpretZ) */
.slider-row {
  display: flex;
  align-items: center;
  gap: 14px;
}
.slider-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
  height: 44px;
}
.slider-row input[type="number"] { width: 92px; flex: none; }

/* ---------------------------------------------------------
   Panneaux : table Z, graphes, résultat
   --------------------------------------------------------- */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel__title {
  font-family: var(--sans);
  font-size: .74rem;
  font-weight: 700;
  letter-spacing: .1em;
  text-transform: uppercase;
  color: var(--muted);
  padding: 14px 22px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
}
.panel__body { padding: 22px; }
.panel--table .panel__body { padding: 14px; overflow-x: auto; }
.panel--graph .panel__body { padding: 16px 18px; }

.panel--result { border-color: var(--accent-line); box-shadow: var(--shadow-md); }
.panel--result .panel__title {
  background: var(--accent-weak);
  color: var(--accent-deep);
  border-bottom-color: var(--accent-line);
}
.result { padding: 22px; }
.result > *:first-child { margin-top: 0; }
.result > *:last-child { margin-bottom: 0; }
.result__waiting {
  margin: 0;
  color: var(--muted);
  font-style: italic;
}

/* Blocs pédagogiques (contenu inchangé, habillage neuf) */
.ci-explain, .explain-box {
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 14px 16px;
  margin: 14px 0;
  line-height: 1.5;
  font-size: .96rem;
}
.ci-explain p, .explain-box p { margin: 7px 0; }
.ci-explain b, .explain-box b { color: var(--ink); }
.ci-explain ul { margin: 6px 0 6px 18px; }

/* KaTeX */
.math-block {
  margin: 14px 0;
  padding: 16px 18px;
  background: var(--accent-weak);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-md);
  overflow-x: auto;
}
.math-block .katex-display { margin: 0; }
.math-fallback {
  background: var(--surface-2);
  border: 1px solid var(--line);
  padding: 12px 14px;
  border-radius: var(--r-md);
  overflow-x: auto;
  white-space: pre;
  font-size: .9rem;
}
.katex { font-size: 1.04em; }

/* Table Z */
.z-table {
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
  font-size: .74rem;
  width: 100%;
  min-width: 520px;
}
.z-table th, .z-table td {
  padding: 3px 5px;
  text-align: right;
  border: 1px solid var(--line);
  color: var(--ink-2);
}
.z-table thead th, .z-table tbody th {
  background: var(--surface-2);
  color: var(--muted);
  font-weight: 700;
  font-size: .72rem;
  position: sticky;
}
.z-table thead th { top: 0; z-index: 1; }
.z-table tbody th { left: 0; }
.z-table td { cursor: pointer; }
.z-table td:hover { background: var(--accent-weak); }

.z-highlight {
  background: var(--accent) !important;
  color: #fff !important;
  font-weight: 700;
  box-shadow: inset 0 0 0 1px var(--accent-deep);
}
.z-picked { outline: 2px solid var(--warn); outline-offset: -2px; }

/* Graphes */
#z-graph, #regression-graph { width: 100%; }
#z-graph svg, #regression-graph svg { display: block; max-width: 100%; }

.z-verdict {
  margin: 0;
  font-size: 1.05rem;
}
.z-verdict--out { color: var(--warn); font-weight: 700; }

/* ---------------------------------------------------------
   Assistant de choix du test
   --------------------------------------------------------- */
.btn-start-wizard {
  display: inline-flex;
  align-items: center;
  min-height: 46px;
  padding: 12px 20px;
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-sm);
  cursor: pointer;
  width: fit-content;
  font-weight: 600;
}
.btn-start-wizard:hover { background: var(--accent-deep); }

.choices { display: flex; flex-direction: column; gap: 8px; margin-top: 12px; }
.choice-card {
  padding: 13px 15px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  cursor: pointer;
  transition: background .15s ease, border-color .15s ease;
  min-height: 44px;
}
.choice-card:hover { background: var(--accent-weak); border-color: var(--accent-line); }
.choice-card.selected {
  background: var(--accent-weak);
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
  font-weight: 600;
  color: var(--accent-deep);
}
.choice-card.disabled { opacity: .4; cursor: not-allowed; }
.shake { animation: shake .3s; }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-4px); }
}

.testresults { padding: 0; margin: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.testresults li {
  padding: 14px 16px;
  background: var(--accent-weak);
  border: 1px solid var(--accent-line);
  border-radius: var(--r-sm);
  font-family: var(--serif);
  font-size: 1.1rem;
  color: var(--accent-deep);
}

/* Shepherd */
.shepherd-element {
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-md);
  font-family: var(--sans);
  max-width: 400px;
}
.shepherd-header {
  background: var(--surface-2) !important;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  padding: 14px 18px !important;
}
.shepherd-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 1.06rem;
  color: var(--ink);
}
.shepherd-text { padding: 16px 18px; color: var(--ink-2); font-size: .96rem; }
.shepherd-footer { padding: 0 18px 16px; gap: 8px; }
.shepherd-element .shepherd-button {
  background: var(--accent);
  color: #fff;
  border-radius: var(--r-sm);
  font-family: var(--sans);
  font-weight: 600;
  font-size: .9rem;
  padding: 9px 16px;
}
.shepherd-element .shepherd-button:not(:disabled):hover { background: var(--accent-deep); color: #fff; }
.shepherd-element .shepherd-button.shepherd-button-secondary {
  background: var(--surface-2);
  color: var(--ink-2);
}
.shepherd-element .shepherd-button.shepherd-button-secondary:not(:disabled):hover { background: var(--line); color: var(--ink); }

/* ---------------------------------------------------------
   Responsive
   --------------------------------------------------------- */
@media (max-width: 1080px) {
  .tool-grid { grid-template-columns: 1fr; }
  .tool-inputs { position: static; }
  .main { padding: 40px 32px 80px; }
}

@media (max-width: 900px) {
  .topbar { display: flex; }
  .layout { grid-template-columns: 1fr; }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    z-index: 50;
    width: min(320px, 86vw);
    height: 100vh;
    transform: translateX(-102%);
    transition: transform .22s ease;
    box-shadow: var(--shadow-md);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .scrim { display: block; }

  .main { padding: 28px 20px 72px; }
  .backlink { display: inline-block; }
  .cards { grid-template-columns: 1fr; }
  .home__title { font-size: 1.9rem; }
}

@media (max-width: 520px) {
  body { font-size: 16px; }
  .main { padding: 22px 16px 64px; }
  .tool-inputs { padding: 18px; }
  .panel__body { padding: 16px; }
  .result { padding: 16px; }
  .panel__title { padding: 12px 16px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
