/*
 * Composants communs de Mon Complice (UX-DR8 à UX-DR17, UX-DR19), écrits à la main d'après DESIGN.md › Components.
 * Toutes les valeurs viennent de jetons.css. Jamais de bouton grisé ni d'attribut disabled ; cibles ≥ 48 px ;
 * aucun texte sous 18 px ; rien ne dépasse, même à 180 px de large (zoom 200 % sur 360 px).
 */

/* Icônes : fichiers SVG monochromes de app/icones/, peints de la couleur du texte. Décoratives (aria-hidden). */
.icone {
  display: inline-block;
  flex: none;
  width: 24px;
  height: 24px;
  background-color: currentColor;
  -webkit-mask: var(--icone) center / contain no-repeat;
  mask: var(--icone) center / contain no-repeat;
}

.icone-retour { --icone: url('../icones/retour.svg'); }
.icone-chevron { --icone: url('../icones/chevron.svg'); }
.icone-coche { --icone: url('../icones/coche.svg'); }
.icone-fermer { --icone: url('../icones/fermer.svg'); }
.icone-document { --icone: url('../icones/document.svg'); }
.icone-information { --icone: url('../icones/information.svg'); }
.icone-horloge { --icone: url('../icones/horloge.svg'); }
.icone-alerte { --icone: url('../icones/alerte.svg'); }
.icone-haut-parleur { --icone: url('../icones/haut-parleur.svg'); }
.icone-telephone { --icone: url('../icones/telephone.svg'); }
.icone-reglages { --icone: url('../icones/reglages.svg'); }

/* Les textes longs passent à la ligne au lieu de dépasser. */
.bouton,
.puce,
.depliant-bouton,
.lien-texte,
.bouton-retour,
.ligne-controle,
.ligne-document,
.ligne-reglage,
.bandeau,
.consigne-prudence,
.mention-ia,
.note-source,
.champ-message,
.panneau,
.dialogue {
  overflow-wrap: anywhere;
}

/* Boutons (UX-DR8) : pilules de 56 px, un seul primaire par écran. */
.bouton {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  min-height: var(--space-tap-min-large);
  padding: var(--space-2) var(--space-6);
  border: 2px solid transparent;
  border-radius: var(--rounded-full);
  font-family: var(--type-body-strong-family);
  font-size: var(--type-body-strong-size);
  font-weight: var(--type-body-strong-weight);
  line-height: var(--type-body-strong-line-height);
  text-align: center;
  text-decoration: none;
  cursor: pointer;
}

.bouton-primaire {
  background: var(--color-leaf);
  border-color: var(--color-leaf);
  color: var(--color-on-dark);
}

.bouton-secondaire {
  background: var(--color-card);
  border-color: var(--color-border-strong);
  color: var(--color-forest);
}

.bouton[hidden] {
  display: none;
}

/* Bouton Écouter (UX-DR18) : même gabarit que le secondaire, avec son haut-parleur. */
.bouton-ecouter {
  background: var(--color-card);
  border-color: var(--color-border-strong);
  color: var(--color-forest);
}

.bouton-plein {
  display: flex;
  width: 100%;
}

/* Petit bouton de 48 px : « Fermer » d'un panneau, action d'un bandeau. */
.bouton-compact {
  min-height: var(--space-tap-min);
  padding-inline: var(--space-4);
}

/* Pilule d'urgence (UX-DR50) : numéro en grand et son usage ; rouge, avec le texte blanc (jamais une couleur seule : le numéro est écrit). */
.pilule-urgence {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 60px;
  padding: var(--space-2) var(--space-5);
  border: 0;
  border-radius: var(--rounded-full);
  background: linear-gradient(160deg, var(--color-emergency), var(--color-emergency-light));
  color: var(--color-on-dark);
  font-family: var(--type-label-family);
  font-size: var(--type-label-size);
  font-weight: var(--type-label-weight);
  line-height: var(--type-label-line-height);
  text-decoration: none;
  overflow-wrap: anywhere;
  cursor: pointer;
}

/* Pilule Personnalisation (pill-settings) : fond carte, bord de 2 px, texte forest. */
.pilule-reglages {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  width: 100%;
  min-height: 60px;
  padding: var(--space-2) var(--space-5);
  border: 2px solid var(--color-border-strong);
  border-radius: var(--rounded-full);
  background: var(--color-card);
  color: var(--color-forest);
  font-family: var(--type-label-family);
  font-size: var(--type-label-size);
  font-weight: var(--type-label-weight);
  line-height: var(--type-label-line-height);
  text-decoration: none;
  overflow-wrap: anywhere;
  cursor: pointer;
}

.pilule-centree {
  justify-content: center;
}

.urgence-numero {
  flex: 0 1 auto;
  min-width: 3ch;
  overflow-wrap: anywhere;
  font-size: var(--type-display-size);
  font-weight: var(--type-display-weight);
  line-height: 1.2;
}

.urgence-usage {
  flex: 1 1 8ch;
  min-width: 0;
}

.liste-urgences > * + * {
  margin-top: var(--space-3);
}

/* Numéro au-dessus de son usage : un long numéro (0 892 705 705) ne serre pas le texte. */
.bouton-ligne {
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  gap: var(--space-1);
  border-radius: var(--rounded-md);
  text-align: left;
}

.bouton-ligne .urgence-numero {
  color: var(--color-forest);
}

.bouton-ligne .urgence-usage {
  flex: 0 1 auto;
}

.urgence-rappel {
  margin-bottom: 0;
  color: var(--color-ink-muted);
  font-family: var(--type-meta-family);
  font-size: var(--type-meta-size);
  font-weight: var(--type-meta-weight);
  line-height: var(--type-meta-line-height);
}

a.ligne-document {
  text-decoration: none;
}

a.bouton-retour {
  text-decoration: none;
}

/* Champ de saisie (UX-DR9) et champ manquant. */
.champ {
  margin: 0 0 var(--space-4);
}

.champ-libelle {
  display: block;
  margin-bottom: var(--space-2);
  font-family: var(--type-label-family);
  font-size: var(--type-label-size);
  font-weight: var(--type-label-weight);
  line-height: var(--type-label-line-height);
}

.champ-saisie {
  display: block;
  width: 100%;
  min-height: var(--space-tap-min-large);
  padding: var(--space-2) var(--space-4);
  border: 2px solid var(--color-border-control);
  border-radius: var(--rounded-sm);
  background: var(--color-card);
  color: var(--color-ink);
  font-family: var(--type-body-family);
  font-size: var(--type-body-size);
  font-weight: var(--type-body-weight);
  line-height: var(--type-body-line-height);
}

.field-missing {
  border: 3px solid var(--color-leaf);
}

.case.field-missing,
.radio.field-missing {
  border-color: var(--color-leaf);
}

.champ-message {
  margin: var(--space-2) 0 0;
  padding-left: var(--space-3);
  border-left: 4px solid var(--color-leaf);
  font-family: var(--type-body-strong-family);
  font-size: var(--type-body-strong-size);
  font-weight: var(--type-body-strong-weight);
  line-height: var(--type-body-strong-line-height);
}

/* Consigne de prudence sous le texte d'un état qui la demande (CODE_INCONNU, HORS_LIGNE) : même composant que .consigne-prudence. */
.consigne-sous-texte {
  display: block;
  margin: var(--space-2) 0 0;
}

/* Groupe de contrôles légendé (UX-DR10). */
.groupe {
  min-width: 0;
  margin: 0 0 var(--space-4);
  padding: 0;
  border: 0;
}

/* Groupe dont aucun choix n'est fait alors qu'il est obligatoire : entouré comme un champ manquant (UX-DR8). */
.groupe.field-missing {
  padding: var(--space-3);
  border: 3px solid var(--color-leaf);
  border-radius: var(--rounded-md);
}

.groupe > legend {
  margin-bottom: var(--space-2);
  padding: 0;
  font-family: var(--type-label-family);
  font-size: var(--type-label-size);
  font-weight: var(--type-label-weight);
  line-height: var(--type-label-line-height);
  color: var(--color-forest);
}

/* Case à cocher, bouton radio, interrupteur : natifs stylés, 28 px, ligne entière touchable. */
.ligne-controle {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  min-height: var(--space-tap-min-large);
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--color-border);
  border-radius: var(--rounded-md);
  background: var(--color-card);
  cursor: pointer;
}

.ligne-controle + .ligne-controle {
  margin-top: var(--space-2);
}

.ligne-texte {
  flex: 1 1 8ch;
  min-width: 0;
}

.case,
.radio {
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  display: inline-grid;
  place-content: center;
  width: 28px;
  height: 28px;
  margin: 0;
  border: 3px solid var(--color-border-control);
  background: var(--color-card);
  cursor: pointer;
}

.case {
  border-radius: 6px;
}

.case:checked {
  background: var(--color-leaf);
  border-color: var(--color-leaf);
}

.case:checked::after {
  content: '';
  width: 18px;
  height: 18px;
  background-color: var(--color-on-dark);
  -webkit-mask: url('../icones/coche.svg') center / contain no-repeat;
  mask: url('../icones/coche.svg') center / contain no-repeat;
}

.radio {
  border-radius: 50%;
}

.radio:checked {
  border-color: var(--color-leaf);
}

.radio:checked::after {
  content: '';
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--color-leaf);
}

.interrupteur {
  flex: none;
  appearance: none;
  -webkit-appearance: none;
  order: 2;
  position: relative;
  width: 60px;
  height: 34px;
  margin: 0;
  border-radius: var(--rounded-full);
  background: var(--color-border-control);
  cursor: pointer;
}

.interrupteur::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 4px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--color-on-dark);
}

.interrupteur:checked {
  background: var(--color-leaf);
}

.interrupteur:checked::after {
  left: 30px;
}

.ligne-interrupteur .ligne-texte {
  order: 1;
}

.interrupteur-etat {
  order: 3;
  min-width: 3ch;
  font-family: var(--type-body-strong-family);
  font-weight: var(--type-body-strong-weight);
}

.interrupteur:not(:checked) ~ .interrupteur-etat .etat-oui,
.interrupteur:checked ~ .interrupteur-etat .etat-non {
  display: none;
}

.ligne-controle:has(:focus-visible) {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 3px;
}

.ligne-controle :focus-visible {
  outline: none;
}

/* Puce en trois rôles (UX-DR11) : choix multiple (aria-pressed), choix exclusif (radio stylée), action. */
.groupe-puces {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
}

.puce {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--space-tap-min);
  padding: var(--space-1) var(--space-4);
  border: 2px solid var(--color-border-control);
  border-radius: var(--rounded-full);
  background: var(--color-card);
  color: var(--color-forest);
  font-family: var(--type-label-family);
  font-size: var(--type-label-size);
  font-weight: var(--type-label-weight);
  line-height: var(--type-label-line-height);
  cursor: pointer;
}

.puce input {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.puce[aria-pressed='true'],
.puce:has(input:checked) {
  padding-inline: calc(var(--space-4) - 1px);
  border: 3px solid var(--color-leaf);
  background: var(--color-mist);
  font-weight: 800;
}

.puce[aria-pressed='true']::before,
.puce:has(input:checked)::before {
  content: '';
  flex: none;
  width: 18px;
  height: 18px;
  background-color: currentColor;
  -webkit-mask: url('../icones/coche.svg') center / contain no-repeat;
  mask: url('../icones/coche.svg') center / contain no-repeat;
}

.puce:has(input:focus-visible) {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 3px;
}

.puce input:focus-visible {
  outline: none;
}

/* Dépliant (UX-DR12). */
.depliant-bouton {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  width: 100%;
  min-height: var(--space-tap-min-large);
  padding: var(--space-2) var(--space-4);
  border: 2px solid var(--color-border-control);
  border-radius: var(--rounded-md);
  background: var(--color-card);
  color: var(--color-forest);
  font-family: var(--type-body-strong-family);
  font-size: var(--type-body-strong-size);
  font-weight: var(--type-body-strong-weight);
  line-height: var(--type-body-strong-line-height);
  text-align: left;
  cursor: pointer;
}

.depliant-bouton[aria-expanded='true'] .icone-chevron {
  transform: rotate(180deg);
}

.depliant-contenu {
  padding: var(--space-3) var(--space-4);
}

/* Lien texte et bouton Retour. */
.lien-texte {
  display: inline-flex;
  align-items: center;
  min-height: var(--space-tap-min);
  color: var(--color-forest);
  font-family: var(--type-label-family);
  font-size: var(--type-label-size);
  font-weight: var(--type-label-weight);
  line-height: var(--type-label-line-height);
  text-decoration: underline;
  text-underline-offset: 3px;
}

.bouton-retour {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  min-height: var(--space-tap-min);
  padding: 0;
  border: 0;
  background: none;
  color: var(--color-forest);
  font-family: var(--type-label-family);
  font-size: var(--type-label-size);
  font-weight: var(--type-label-weight);
  line-height: var(--type-label-line-height);
  cursor: pointer;
}

/* Panneau (UX-DR13) et dialogue de confirmation (UX-DR14). */
.couche-fond {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(12, 28, 46, 0.45);
}

.panneau {
  position: fixed;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 101;
  width: 100%;
  max-width: var(--space-column-max);
  max-height: 90vh;
  margin-inline: auto;
  padding: var(--space-5) var(--space-gutter) var(--space-6);
  overflow-y: auto;
  border-radius: var(--rounded-lg) var(--rounded-lg) 0 0;
  background: var(--color-cream);
  color: var(--color-ink);
  box-shadow: var(--shadow-panel);
  animation: montee 200ms ease-out;
}

.panneau[hidden],
.dialogue-fond[hidden] {
  display: none;
}

.panneau-entete {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
}

.panneau-entete h2 {
  flex: 1 1 8ch;
  min-width: 0;
  margin: 0;
}

.panneau > .bouton-compact:last-child {
  margin-top: var(--space-4);
}

.dialogue-fond {
  position: fixed;
  inset: 0;
  z-index: 102;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-gutter);
  background: rgba(12, 28, 46, 0.45);
}

.dialogue {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  width: 100%;
  max-width: 440px;
  max-height: 90vh;
  padding: var(--space-6);
  overflow-y: auto;
  border-radius: var(--rounded-lg);
  background: var(--color-card);
  color: var(--color-ink);
}

.dialogue h2 {
  margin: 0;
}

.dialogue p {
  margin: 0;
}

@keyframes montee {
  from { transform: translateY(24px); opacity: 0; }
  to { transform: none; opacity: 1; }
}

/* Bandeau d'état (UX-DR15) : icône, phrase, au plus une action ; jamais rouge. */
.bandeau {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border-left: 6px solid var(--color-ink-muted);
  border-radius: var(--rounded-md);
  background: var(--color-card);
  box-shadow: var(--shadow-card);
}

.bandeau[hidden] {
  display: none;
}

.bandeau-texte {
  flex: 1 1 8ch;
  min-width: 0;
}

/* Action du bandeau : petit bouton primaire de 48 px, posé avec .bouton .bouton-compact (hors du compte des primaires de l'écran). */
.bandeau-action {
  border-color: var(--color-leaf);
  background: var(--color-leaf);
  color: var(--color-on-dark);
}

/* Indicateur d'attente (UX-DR16) : phrase et trois points lents, figés sous « mouvement réduit ». */
.attente {
  color: var(--color-forest);
  font-family: var(--type-title-family);
  font-size: var(--type-title-size);
  font-weight: var(--type-title-weight);
  line-height: var(--type-title-line-height);
}

.attente-points {
  display: inline-flex;
  gap: var(--space-2);
  margin-left: var(--space-2);
  vertical-align: middle;
}

.attente-points span {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: currentColor;
  animation: attente 2.4s ease-in-out infinite;
}

.attente-points span:nth-child(2) { animation-delay: 0.4s; }
.attente-points span:nth-child(3) { animation-delay: 0.8s; }

@keyframes attente {
  0%, 100% { opacity: 0.25; }
  50% { opacity: 1; }
}

/* Consigne de prudence, mention IA, note de source (UX-DR17) : jamais de rouge. */
.consigne-prudence {
  margin: 0 0 var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-left: 6px solid var(--color-forest);
  border-radius: var(--rounded-md);
  background: var(--color-card);
  font-family: var(--type-body-strong-family);
  font-size: var(--type-body-strong-size);
  font-weight: var(--type-body-strong-weight);
  line-height: var(--type-body-strong-line-height);
}

.mention-ia {
  margin: 0 0 var(--space-4);
  color: var(--color-ink-muted);
  font-family: var(--type-meta-family);
  font-size: var(--type-meta-size);
  font-weight: var(--type-meta-weight);
  line-height: var(--type-meta-line-height);
}

.note-source {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-3);
  border-left: 4px solid var(--color-border-strong);
  color: var(--color-ink-muted);
  font-family: var(--type-meta-family);
  font-size: var(--type-meta-size);
  font-weight: var(--type-meta-weight);
  line-height: var(--type-meta-line-height);
}

/* Ligne de document (UX-DR19) et ligne de réglage. */
.ligne-document {
  display: block;
  width: 100%;
  min-height: 72px;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--rounded-md);
  background: var(--color-card);
  color: var(--color-ink);
  font: inherit;
  text-align: left;
  cursor: pointer;
}

.ligne-document-categorie {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--color-forest);
  font-family: var(--type-label-family);
  font-size: var(--type-label-size);
  font-weight: var(--type-label-weight);
  line-height: var(--type-label-line-height);
}

.ligne-document-titre {
  display: block;
  font-family: var(--type-body-strong-family);
  font-weight: var(--type-body-strong-weight);
}

.ligne-document-date {
  display: block;
  color: var(--color-ink-muted);
  font-family: var(--type-meta-family);
  font-size: var(--type-meta-size);
  font-weight: var(--type-meta-weight);
  line-height: var(--type-meta-line-height);
}

/* Proche enregistré (story 1.12) : nom, contact, puis Modifier et Retirer côte à côte. */
.proche {
  cursor: default;
}

.proche-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2);
  margin-top: var(--space-3);
}

.ligne-reglage {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  min-height: var(--space-tap-min-large);
  padding: var(--space-2) var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--rounded-md);
  background: var(--color-card);
}

label.ligne-reglage {
  cursor: pointer;
}

.ligne-reglage:has(:focus-visible) {
  outline: 3px solid var(--color-focus-ring);
  outline-offset: 3px;
}

.ligne-reglage :focus-visible {
  outline: none;
}

/* Page de démonstration. */
.demo-section {
  margin-bottom: var(--space-7);
}

.demo-texte-long {
  overflow-wrap: anywhere;
}

.demo-liste {
  margin: 0 0 var(--space-4);
  padding: 0;
  list-style: none;
}

.demo-liste > li + li {
  margin-top: var(--space-2);
}

.demo-pile > * + * {
  margin-top: var(--space-3);
}

@media (prefers-reduced-motion: reduce) {
  .panneau { animation: none; }
  .attente-points span { animation: none; opacity: 1; }
}

/* Aperçu de l'écran Personnalisation : un exemple de texte et de bouton, qui suit les réglages en direct. */
.apercu {
  margin: 0 0 var(--space-section-gap);
  padding: var(--space-4);
  border: 1px solid var(--color-border);
  border-radius: var(--rounded-md);
  background: var(--color-card);
}

.apercu h2 {
  margin-top: 0;
}

/* Guide d'installation (story 1.7) : pas à pas numéroté, une phrase par étape. */
.guide-etapes {
  margin: 0 0 var(--space-4);
  padding-left: var(--space-6);
}

.guide-etapes > li + li {
  margin-top: var(--space-3);
}

/* Badge de niveau (UX-DR7) : mot + icône + phrase fixe, jamais la couleur seule. */
.icone-niveau-rouge { --icone: url('../icones/niveau-rouge.svg'); }
.icone-niveau-orange { --icone: url('../icones/niveau-orange.svg'); }
.icone-niveau-vert { --icone: url('../icones/niveau-vert.svg'); }

.badge-niveau {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-2);
  margin: 0 0 var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: 2px solid currentColor;
  border-radius: var(--rounded-md);
  font-family: var(--type-body-strong-family);
  font-size: var(--type-body-strong-size);
  font-weight: var(--type-body-strong-weight);
  line-height: var(--type-body-strong-line-height);
  overflow-wrap: anywhere;
}

.badge-mot { font-weight: 800; }
.badge-rouge { background: var(--color-level-red-bg); color: var(--color-level-red-ink); }
.badge-orange { background: var(--color-level-orange-bg); color: var(--color-level-orange-ink); }
.badge-vert { background: var(--color-level-green-bg); color: var(--color-level-green-ink); }

/* Écran de résultat (UX-DR30). */
.personnage-essai {
  display: block;
  width: 96px;
  height: 144px;
  max-width: 100%;
  margin: var(--space-3) auto;
  object-fit: contain;
}

.bloc-resultat { margin: 0 0 var(--space-5); overflow-wrap: anywhere; }
.bloc-resultat.fond-rouge { padding: var(--space-3) var(--space-4); border-radius: var(--rounded-md); background: var(--color-level-red-bg); }
.bloc-resultat.fond-orange { padding: var(--space-3) var(--space-4); border-radius: var(--rounded-md); background: var(--color-level-orange-bg); }
.bloc-resultat.fond-vert { padding: var(--space-3) var(--space-4); border-radius: var(--rounded-md); background: var(--color-level-green-bg); }
.bloc-resultat .badge-niveau { background: var(--color-card); }
.liste-raisons { margin: 0; padding-left: var(--space-6); }
.liste-raisons > li + li { margin-top: var(--space-2); }

/* Le courrier d'exemple de l'essai (story 1.11, correctif) : une feuille posée sur le fond, lisible mais clairement à part. */
.courrier-exemple {
  margin: 0;
  padding: var(--space-4);
  border: 1px solid var(--color-border-strong);
  border-radius: var(--rounded-md);
  background: var(--color-card);
  box-shadow: var(--shadow-card);
  overflow-wrap: anywhere;
}

.courrier-exemple p { margin: 0 0 var(--space-3); }
.courrier-exemple p:last-child { margin-bottom: 0; }
