/* Couleurs en variables ; thème clair par défaut, sombre selon le système. */
:root {
  --fond: #f6f5f1;
  --surface: #ffffff;
  --texte: #1b1d21;
  --discret: #5d636d;
  --bord: #d9d6cd;
  --accent: #1f4fd8;
  --sur-accent: #ffffff;
  --danger: #b3261e;
  --jm: #e8eefc;
  --voix: #eef3ea;
  color-scheme: light dark;
}

@media (prefers-color-scheme: dark) {
  :root {
    --fond: #14161a;
    --surface: #1d2025;
    --texte: #eceae4;
    --discret: #9aa1ab;
    --bord: #343942;
    --accent: #6d93ff;
    --sur-accent: #0c1020;
    --danger: #ff8a80;
    --jm: #1f2a44;
    --voix: #212a22;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--fond);
  color: var(--texte);
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  padding: env(safe-area-inset-top) max(16px, env(safe-area-inset-right))
           max(12px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.entete {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 48px;
}
h1 { margin: 0; font-size: 1.25rem; }
h2 { margin: 0 0 4px; font-size: 1.2rem; }

.message {
  margin: 0 0 8px;
  padding: 10px 12px;
  border: 1px solid var(--danger);
  border-radius: 10px;
  color: var(--danger);
}

.ecran { flex: 1; min-height: 0; }

/* Boutons */
button {
  min-height: 48px;
  padding: 0 20px;
  border: 1px solid var(--bord);
  border-radius: 14px;
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  font-weight: 600;
  touch-action: manipulation;
}
button:disabled { opacity: 0.5; }
button.principal {
  width: 100%;
  min-height: 72px;
  border-color: var(--accent);
  background: var(--accent);
  color: var(--sur-accent);
  font-size: 1.25rem;
}
button.principal.actif { background: var(--danger); border-color: var(--danger); color: var(--surface); }
button.discret { min-height: 44px; border-color: transparent; background: transparent; color: var(--discret); }
button.secondaire { min-width: 96px; }

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

/* Formulaires (appairage, réglages) */
.formulaire {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 480px;
  margin: 8vh auto 0;
}
.aide { margin: 0; color: var(--discret); }
label { font-weight: 600; }
input {
  width: 100%;
  min-height: 52px;
  padding: 0 14px;
  border: 1px solid var(--bord);
  border-radius: 12px;
  background: var(--surface);
  color: var(--texte);
  font: inherit;
  font-size: 1.25rem; /* 16 px minimum : pas de zoom automatique sur iPhone */
}

/* Écran principal */
.principal-ecran { display: flex; flex-direction: column; gap: 8px; }
.principal-ecran[hidden] { display: none; }

.ligne-etat { display: flex; justify-content: space-between; gap: 12px; align-items: baseline; }
.statut { margin: 0; font-weight: 600; }
.quota { margin: 0; color: var(--discret); white-space: nowrap; font-size: 0.9rem; }

.defilement {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  padding: 4px 0;
}
.fil { display: flex; flex-direction: column; gap: 8px; }
.fil:empty::before { content: "La conversation apparaît ici."; color: var(--discret); }

.bloc { padding: 10px 12px; border-radius: 12px; }
.bloc.jm { background: var(--jm); }
.bloc.voix { background: var(--voix); }
.locuteur { display: block; color: var(--discret); font-size: 0.85rem; font-weight: 700; }
.paroles { margin: 2px 0 0; overflow-wrap: anywhere; }

.activite { margin: 0; padding: 0; list-style: none; color: var(--discret); font-size: 0.9rem; }
.activite:empty { display: none; }
.activite li { padding: 2px 0; overflow-wrap: anywhere; }

.resultats { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
.resultat {
  padding: 12px;
  border: 1px solid var(--bord);
  border-radius: 12px;
  background: var(--surface);
  overflow-wrap: anywhere;
}
.resultat p, .resultat ul { margin: 0 0 8px; }
.resultat > :last-child { margin-bottom: 0; }
.resultat ul { padding-left: 1.25rem; }
.resultat .titre { font-weight: 700; }
code {
  padding: 1px 5px;
  border-radius: 5px;
  background: var(--bord);
  font: 0.9em ui-monospace, Menlo, monospace;
}

.note { margin: 0; text-align: center; color: var(--discret); }
.actions { display: flex; flex-direction: column; gap: 8px; align-items: stretch; padding-top: 4px; }
.actions .secondaire { align-self: flex-end; }

@media (prefers-reduced-motion: no-preference) {
  button { transition: background-color 0.15s, opacity 0.15s; }
  .principal-ecran .statut[data-etat="connexion"] { animation: respire 1.4s ease-in-out infinite; }
  @keyframes respire { 50% { opacity: 0.45; } }
}
