/* ===== SYLVARIS — Reset & Base ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { scroll-behavior: smooth; font-size: var(--fz-base); }

body {
  font-family: var(--font-body);
  background: var(--bg-page);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--text-primary);
  line-height: 1.25;
}

a { color: var(--accent); text-decoration: none; transition: color var(--tr-fast); }
a:hover { color: var(--accent-hover); }

img { max-width: 100%; height: auto; display: block; }

button, input, select, textarea {
  font-family: inherit;
  font-size: inherit;
}

button { cursor: pointer; border: none; background: none; }

ul { list-style: none; }

/* ===== Boutons ===== */
.btn {
  display: inline-flex;
  align-items: center;
  /* Centré horizontalement aussi. Un .btn est en inline-flex : tant qu'il fait
     la largeur de son texte, la question ne se pose pas. Elle se pose dès qu'il
     est étiré — item d'une colonne flex, comme les boutons « Se connecter » et
     « Créer mon compte » de leurs formulaires, ou largeur imposée : sans cette
     ligne, le texte reste collé au bord gauche du bouton. */
  justify-content: center;
  gap: var(--space-xs);
  padding: 9px 20px;
  border-radius: var(--radius-pill);
  font-size: var(--fz-sm);
  font-weight: 600;
  transition: background var(--tr-fast), transform var(--tr-fast), box-shadow var(--tr-fast);
  cursor: pointer;
  border: 2px solid transparent;
}

.btn-primary {
  background: var(--accent);
  color: var(--text-on-dark);
}
.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(45,74,45,.25);
  color: var(--text-on-dark);
}

.btn-outline {
  background: transparent;
  color: var(--accent);
  border-color: var(--accent);
}
.btn-outline:hover {
  background: var(--accent);
  color: var(--text-on-dark);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover { background: var(--clr-sage-pale); }

/* Suppression : un pastel bordé, pas un aplat vif. La bordure lui garde une
   silhouette nette à côté des boutons fantômes, qui n'en ont pas. */
.btn-danger {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger-border);
}
.btn-danger:hover {
  background: var(--danger-bg-hover);
  color: var(--danger-text);
  border-color: var(--danger);
}

/* Le contraste entre actif et inactif s'est réduit avec le pastel : sans cette
   règle, un « Supprimer » désactivé (catégorie encore utilisée) ressemblait
   trait pour trait à un bouton cliquable. */
.btn:disabled,
.btn[disabled] {
  opacity: .45;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.btn-sm { padding: 5px 14px; font-size: var(--fz-xs); }
.btn-lg { padding: 13px 30px; font-size: var(--fz-md); }

/* ===== Formulaires ===== */
/* min-width: 0 : posé comme item d'une grille ou d'une ligne flex (colonne de
   .vegetal-form__grid, cellule de .inline-fields…), un .form-group ne doit
   jamais refuser de rétrécir sous la largeur naturelle de son contenu — un
   champ un peu large forcerait alors tout le conteneur, puis la page, à
   déborder plutôt que de se resserrer. Sans effet là où il est simplement
   empilé dans un flux normal. */
.form-group { display: flex; flex-direction: column; gap: var(--space-xs); min-width: 0; }
.form-label { font-size: var(--fz-sm); font-weight: 600; color: var(--text-secondary); }

/* Message de résultat d'un formulaire — « Enregistré », « Nom déjà pris ».
   Le même dessin existait déjà, recopié dans le <style> de profil.php,
   admin/permissions.php et admin/champs-obligatoires.php sous le nom
   .profil-alert. Il est ici pour que la page suivante ne le recopie pas une
   quatrième fois ; les trois copies pourront le rejoindre à l'occasion. */
.alerte {
  padding: 12px 16px;
  border-radius: var(--radius-md);
  font-size: var(--fz-sm);
  font-weight: 600;
  margin-bottom: var(--space-md);
}
.alerte--succes { background: #D1FAE5; border-left: 4px solid #10B981; color: #065F46; }
.alerte--erreur { background: #FEE2E2; border-left: 4px solid #DC2626; color: #991B1B; }
[data-theme="dark"] .alerte--succes { background: rgba(16,185,129,.12); color: #6EE7B7; border-left-color: #6EE7B7; }
[data-theme="dark"] .alerte--erreur { background: rgba(220,38,38,.12);  color: #FCA5A5; border-left-color: #FCA5A5; }

.form-control {
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--bg-card);
  color: var(--text-primary);
  transition: border-color var(--tr-fast), box-shadow var(--tr-fast);
  outline: none;
}
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(62,107,62,.15);
}

select.form-control { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%235A7A59' d='M6 8L0 0h12z'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 36px; }

/* ===== Badges / Pills ===== */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 10px;
  border-radius: var(--radius-pill);
  font-size: var(--fz-xs);
  font-weight: 600;
}
.badge-sage   { background: var(--clr-sage-pale); color: var(--clr-forest-mid); }
.badge-forest { background: var(--clr-forest);    color: #fff; }
.badge-bark   { background: #F3E8DD;              color: var(--clr-bark); }

/* ===== Utilitaires ===== */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); }
.mt-sm  { margin-top: var(--space-sm); }
.mt-md  { margin-top: var(--space-md); }
.mt-lg  { margin-top: var(--space-lg); }
.mb-md  { margin-bottom: var(--space-md); }
.gap-sm { gap: var(--space-sm); }

/* ===== Toast notifications ===== */
#toast-container {
  position: fixed;
  bottom: var(--space-lg);
  right: var(--space-lg);
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: var(--space-sm);
}
.toast {
  padding: 12px 20px;
  border-radius: var(--radius-md);
  color: #fff;
  font-size: var(--fz-sm);
  font-weight: 600;
  box-shadow: var(--shadow-hover);
  animation: toastIn var(--tr-slow) forwards;
  max-width: 340px;
}
.toast-success { background: var(--clr-forest-mid); }
.toast-error   { background: #DC2626; }
.toast-info    { background: #2563EB; }
@keyframes toastIn {
  from { opacity: 0; transform: translateX(40px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ===== Loading spinner ===== */
.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid var(--clr-sage-light);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  margin: auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== Scrollbar personnalisée ===== */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: var(--clr-sage-pale); }
::-webkit-scrollbar-thumb { background: var(--clr-sage); border-radius: 4px; }

/* ═══════════════════════════════════════════════════════════════════════════
   Mot défini — info-bulle au survol
   ═══════════════════════════════════════════════════════════════════════════
   Posée le 05/09/2026 : certaines valeurs des fiches portent une définition,
   écrite par Didier depuis admin/valeurs.php. Le mot se signale discrètement,
   et sa définition apparaît au survol, au clavier, ou à l'appui sur mobile.

   ⚠ Le soulignement est en `text-decoration` pointillé et non en `border-bottom` :
   une bordure sépare le mot de sa ligne de base d'un pixel, ce qui se voit sur une
   liste où les mots alternent définis et non définis.

   ⚠ `:focus-within` autant que `:hover` : sur un écran tactile il n'y a pas de
   survol, mais un élément focusable réagit à l'appui. C'est ce qui rend la
   définition atteignable au doigt — et au clavier, ce qui est la même exigence. */
.def {
  position: relative;
  text-decoration: underline dotted var(--clr-sage);
  text-underline-offset: 3px;
  cursor: help;
  outline: none;
}
.def:hover, .def:focus-within { text-decoration-color: var(--accent); }

.def__bulle {
  position: absolute;
  bottom: calc(100% + 8px);
  left: 0;
  z-index: 40;
  width: max-content;
  max-width: 260px;
  padding: 8px 11px;
  border-radius: var(--radius-md);
  background: var(--clr-forest);
  color: #fff;
  font-size: var(--fz-xs);
  font-weight: 400;
  line-height: 1.5;
  text-decoration: none;
  /* Justifié à la demande de Didier, avec la césure **obligatoirement** : dans une
     bulle de 260 px et à 11 px de corps, une ligne ne tient que six ou sept mots.
     Justifier sans césure y creuse des rivières blanches dès qu'un mot long arrive
     — et « argilo-limoneuse » ou « semi-persistant » sont précisément le sujet.
     `hyphens` s'appuie sur le `lang="fr"` de <html> : sans lui, le navigateur ne
     saurait pas où couper. */
  text-align: justify;
  hyphens: auto;
  box-shadow: var(--shadow-modal);
  /* `visibility` en plus de l'opacité : sans elle la bulle reste cliquable et
     survolable une fois « cachée », et elle clignote au passage de la souris. */
  opacity: 0;
  visibility: hidden;
  transition: opacity var(--tr-fast), visibility var(--tr-fast);
  pointer-events: none;
}
.def:hover .def__bulle,
.def:focus-within .def__bulle { opacity: 1; visibility: visible; }

/* La petite pointe, tournée vers le mot. */
.def__bulle::after {
  content: '';
  position: absolute;
  top: 100%;
  left: 14px;
  border: 6px solid transparent;
  border-top-color: var(--clr-forest);
}

/* ---- Bulle ancrée à droite ----
   Posée par initDefinitions() (main.js) quand la bulle déborderait par la droite —
   ce qui arrive dès que le mot défini est en fin de ligne, et c'est fréquent : les
   valeurs s'affichent en listes qui remplissent leur colonne.

   ⚠ Pourquoi une classe posée en JS plutôt qu'une règle CSS : le CSS ne sait pas
   où le mot se trouve dans sa ligne. `left: 50%` centrerait la bulle sans empêcher
   le débordement, et l'ancrage natif (`position-anchor`) n'est pas encore sûr. */
.def--fin .def__bulle        { left: auto; right: 0; }
.def--fin .def__bulle::after { left: auto; right: 14px; }

/* Sur écran étroit, une bulle ancrée à gauche déborde dès que le mot est en fin
   de ligne. On la recentre sur le conteneur plutôt que sur le mot. */
@media (max-width: 600px) {
  .def__bulle { left: 0; right: auto; max-width: min(260px, 78vw); }
}
