:root {
  --accent: #2dd4bf;
  --accent-fort: #0d9488;
  --accent-soft: #0f2e2b;
  --highlight: #fb923c;
  --highlight-fort: #ea580c;
  --bg: #000000;
  --surface: #111111;
  --surface-alt: #1a1a1a;
  --border: #2a2a2a;
  --text: #ffffff;
  --muted: #b3b3b3;
  --ok: #34d399;
  --alerte: #f87171;
  --rayon: 14px;
  --serif: "Georgia", "Times New Roman", serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="clair"] {
  --accent: #0d9488;
  --accent-fort: #0f766e;
  --accent-soft: #ccfbf1;
  --highlight: #ea580c;
  --highlight-fort: #c2410c;
  --bg: #eef2f6;
  --surface: #ffffff;
  --surface-alt: #f3f6f9;
  --border: #d5dde6;
  --text: #111827;
  --muted: #5b6470;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.55;
  -webkit-text-size-adjust: 100%;
}

a { color: var(--accent); text-decoration: none; }
/* Les liens des reponses doivent se voir comme cliquables : plus de bloc de sources separe. */
.bulle a { text-decoration: underline; text-underline-offset: 2px; }
.bulle a:hover { color: var(--accent-fort); }
a:hover { text-decoration: underline; }

.entete {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: .7rem;
  padding: .6rem .9rem;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.marque { display: flex; align-items: center; gap: .55rem; color: var(--text); }
.marque img { width: 34px; height: 48px; object-fit: contain; }
.marque b { font-size: 1.05rem; letter-spacing: .01em; }
.marque small { display: block; color: var(--muted); font-size: .72rem; font-weight: 400; letter-spacing: .04em; text-transform: uppercase; }

.entete nav { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.entete nav a, .entete nav button { font-size: .9rem; color: var(--muted); background: none; border: 0; cursor: pointer; }
.entete nav a:hover, .entete nav button:hover { color: var(--text); }

.bouton {
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
  padding: .6rem 1.1rem; border-radius: 999px; border: 1px solid transparent;
  background: var(--accent); color: #04231f; font-weight: 600; font-size: .95rem; cursor: pointer;
}
[data-theme="clair"] .bouton { color: #ffffff; }
.bouton:hover { filter: brightness(1.06); text-decoration: none; }
.bouton--fantome { background: transparent; border-color: var(--border); color: var(--text); }
.bouton--petit { padding: .4rem .8rem; font-size: .85rem; }

.mise-en-page { display: flex; min-height: calc(100vh - 60px); }

/* ---------------- colonne historique ---------------- */
.historique {
  width: 264px; flex: 0 0 264px; border-right: 1px solid var(--border);
  background: var(--surface); padding: .8rem; display: flex; flex-direction: column; gap: .5rem;
}
.historique h2 { margin: .2rem .3rem .4rem; font-size: .8rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); font-weight: 600; }
.historique ul { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.historique li { display: flex; align-items: center; border-radius: 10px; }
.historique li.actif { background: var(--surface-alt); }
.historique li a { flex: 1; padding: .5rem .6rem; color: var(--text); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.historique li .supprime { border: 0; background: none; color: var(--muted); cursor: pointer; padding: .3rem .5rem; font-size: 1rem; line-height: 1; }
.historique li .supprime:hover { color: var(--alerte); }

/* ---------------- fil de discussion ---------------- */
.principal { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.fil { flex: 1; overflow-y: auto; padding: 1.2rem 1rem 0.5rem; scroll-behavior: smooth; }
.fil-inner { max-width: 780px; margin: 0 auto; display: flex; flex-direction: column; gap: 1.1rem; }

.accueil-intro { text-align: center; padding: 2.4rem 1rem 1.2rem; }
.accueil-intro img { width: 96px; height: 135px; object-fit: contain; }
.accueil-intro h1 { font-family: var(--serif); font-size: 1.75rem; margin: .6rem 0 .3rem; }
.accueil-intro p { color: var(--muted); margin: 0 auto; max-width: 34rem; }
.puces { display: flex; flex-wrap: wrap; gap: .45rem; justify-content: center; margin-top: 1.1rem; }
.puces button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: .45rem .85rem; font-size: .85rem; cursor: pointer;
}
.puces button:hover { border-color: var(--accent); color: var(--accent); }

.message { display: flex; gap: .7rem; align-items: flex-start; }
.message .avatar { width: 30px; height: 42px; flex: 0 0 30px; object-fit: contain; margin-top: .15rem; }
.message .bulle { background: var(--surface); border: 1px solid var(--border); border-radius: var(--rayon); padding: .75rem .95rem; max-width: 100%; overflow-wrap: anywhere; }
.message--moi { flex-direction: row-reverse; }
.message--moi .bulle { background: var(--accent-soft); border-color: color-mix(in srgb, var(--accent) 35%, transparent); }
.message--moi .avatar { display: none; }
.message .bulle p { margin: 0 0 .55rem; }
.message .bulle p:last-child { margin-bottom: 0; }
.message .bulle ul, .message .bulle ol { margin: .3rem 0 .6rem; padding-left: 1.2rem; }
.message .bulle code { background: var(--surface-alt); border-radius: 5px; padding: .1rem .3rem; font-size: .9em; }
.message .bulle pre { background: var(--surface-alt); padding: .7rem; border-radius: 8px; overflow-x: auto; }

.mention-mode { display: inline-block; margin-top: .5rem; font-size: .72rem; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: .15rem .55rem; }

/* ---------------- saisie ---------------- */
.saisie { border-top: 1px solid var(--border); background: var(--bg); padding: .7rem 1rem 1rem; }
.saisie-inner { max-width: 780px; margin: 0 auto; display: flex; gap: .5rem; align-items: flex-end; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: .45rem .45rem .45rem .9rem; }
.saisie textarea {
  flex: 1; resize: none; border: 0; outline: 0; background: transparent; color: var(--text);
  font: inherit; padding: .45rem 0; max-height: 160px; min-height: 26px;
}
.saisie .envoi { width: 40px; height: 40px; border-radius: 50%; border: 0; background: var(--accent); color: #04231f; font-size: 1.1rem; cursor: pointer; flex: 0 0 40px; }
.saisie .envoi:disabled { opacity: .45; cursor: default; }
.aide-saisie { max-width: 780px; margin: .45rem auto 0; display: flex; justify-content: space-between; gap: .6rem; font-size: .75rem; color: var(--muted); }
.aide-saisie kbd { font-family: inherit; }

/* ---------------- bandeau anonyme / quota ---------------- */
.bandeau { max-width: 780px; margin: .8rem auto 0; border: 1px solid color-mix(in srgb, var(--highlight) 45%, transparent); background: color-mix(in srgb, var(--highlight) 12%, transparent); border-radius: var(--rayon); padding: .6rem .85rem; font-size: .88rem; display: flex; gap: .7rem; align-items: center; flex-wrap: wrap; }
.bandeau .bouton { margin-left: 0; flex: 0 0 auto; }
.bandeau > span { flex: 1 1 14rem; }
.bandeau .bouton:first-of-type { margin-left: auto; }

/* ---------------- attente : dessin anime de Gwadix ---------------- */
#attente-overlay { position: fixed; inset: 0; z-index: 900; display: none; align-items: center; justify-content: center; }
#attente-overlay.visible { display: flex; }
#attente-overlay::before { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.55); }
[data-theme="clair"] #attente-overlay::before { background: rgba(15,23,42,.28); }
.attente-boite { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 18px; padding: .9rem 1.2rem 1rem; display: flex; flex-direction: column; align-items: center; gap: .4rem; box-shadow: 0 18px 48px rgba(0,0,0,.35); }
.attente-boite video { width: 120px; height: 120px; object-fit: contain; background: var(--bg); border-radius: 12px; }
.attente-boite p { margin: 0; font-size: .85rem; color: var(--muted); }

/* ---------------- pages de compte ---------------- */
.page-etroite { max-width: 460px; margin: 2.2rem auto; padding: 0 1rem; }
.carte { background: var(--surface); border: 1px solid var(--border); border-radius: var(--rayon); padding: 1.4rem; }
.carte h1 { font-family: var(--serif); font-size: 1.5rem; margin: 0 0 .3rem; }
.carte p.intro { color: var(--muted); margin-top: 0; }
label { display: block; font-size: .85rem; color: var(--muted); margin: .8rem 0 .25rem; }
input[type="email"], input[type="password"], input[type="text"], input[type="tel"] {
  width: 100%; padding: .65rem .8rem; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface-alt); color: var(--text); font: inherit;
}
input:focus { outline: 2px solid color-mix(in srgb, var(--accent) 55%, transparent); outline-offset: 1px; }
.carte .bouton { width: 100%; margin-top: 1rem; }
.separateur { display: flex; align-items: center; gap: .6rem; color: var(--muted); font-size: .8rem; margin: 1.1rem 0 .8rem; }
.separateur::before, .separateur::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.oauth { display: flex; flex-direction: column; gap: .5rem; }
.oauth a { display: flex; align-items: center; justify-content: center; gap: .5rem; padding: .6rem; border-radius: 10px; border: 1px solid var(--border); color: var(--text); background: var(--surface-alt); font-size: .92rem; }
.erreur { background: color-mix(in srgb, var(--alerte) 15%, transparent); border: 1px solid color-mix(in srgb, var(--alerte) 45%, transparent); color: var(--text); border-radius: 10px; padding: .55rem .75rem; font-size: .88rem; margin-bottom: .8rem; }
.succes { background: color-mix(in srgb, var(--ok) 15%, transparent); border: 1px solid color-mix(in srgb, var(--ok) 45%, transparent); border-radius: 10px; padding: .55rem .75rem; font-size: .88rem; margin-bottom: .8rem; }
.petit { font-size: .8rem; color: var(--muted); }
.lien-bas { text-align: center; margin-top: 1rem; font-size: .88rem; color: var(--muted); }

.jauge { margin: .7rem 0; }
.jauge .titre { display: flex; justify-content: space-between; font-size: .84rem; color: var(--muted); margin-bottom: .25rem; }
.jauge .barre { height: 8px; border-radius: 999px; background: var(--surface-alt); overflow: hidden; }
.jauge .barre i { display: block; height: 100%; background: var(--accent); }

.legal { max-width: 720px; margin: 2rem auto; padding: 0 1rem 3rem; }
.legal h1 { font-family: var(--serif); }
.legal p, .legal li { color: var(--text); }

.pied { border-top: 1px solid var(--border); padding: 1rem; text-align: center; font-size: .78rem; color: var(--muted); }
.pied a { color: var(--muted); margin: 0 .4rem; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

@media (max-width: 860px) {
  .historique { display: none; }
  .historique.ouvert { display: flex; position: fixed; inset: 60px 0 0 0; width: 100%; z-index: 40; }
  .accueil-intro { padding-top: 1.4rem; }
  .accueil-intro h1 { font-size: 1.45rem; }
}

/* ---------------- barre de discussion et partage ---------------- */
.barre-discussion {
  display: flex; align-items: center; gap: .7rem; justify-content: space-between;
  padding: .5rem .9rem; border-bottom: 1px solid var(--border); background: var(--bg);
}
.barre-discussion[hidden] { display: none; }
.barre-discussion .titre-discussion {
  font-size: .9rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.partage-resultat {
  display: flex; gap: .5rem; align-items: center; padding: .5rem .9rem;
  border-bottom: 1px solid var(--border); background: var(--surface);
}
.partage-resultat input {
  flex: 1; min-width: 0; font-size: .85rem; padding: .4rem .6rem; color: var(--text);
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
}

/* ---------------- page de discussion partagée ---------------- */
.partage { max-width: 780px; margin: 0 auto; padding: 1.2rem 1rem 3rem; }
.partage-entete { display: flex; gap: .9rem; align-items: center; margin-bottom: 1.4rem; }
.partage-entete img { width: 56px; height: 78px; object-fit: contain; }
.partage-entete h1 { font-family: var(--serif); font-size: 1.35rem; margin: 0 0 .2rem; }
.partage-entete .petit { margin: 0; }
.fil-partage { display: flex; flex-direction: column; gap: 1rem; }
.partage-pied {
  margin-top: 2rem; padding-top: 1.2rem; border-top: 1px solid var(--border);
  display: flex; flex-wrap: wrap; gap: .8rem; align-items: center;
}

@media (max-width: 860px) {
  /* iOS agrandit la page au focus si le champ fait moins de 16 px. */
  .saisie textarea { font-size: 16px; }
  .fil { padding-bottom: 1rem; }
}

/* ---------------- page de discussion : hauteur fixe ----------------
   La page ne defile pas : c'est le fil qui defile, sinon la zone de saisie sort de l'ecran
   sur mobile et le defilement automatique n'arrive plus au dernier message. */
.page-chat { height: 100dvh; overflow: hidden; display: flex; flex-direction: column; }
.page-chat .entete { flex: 0 0 auto; }
.page-chat .mise-en-page { flex: 1 1 auto; min-height: 0; overflow: hidden; }
.page-chat .principal { max-height: 100%; min-height: 0; }
.page-chat .pied { flex: 0 0 auto; padding: .45rem; font-size: .7rem; }
.page-chat .fil { overscroll-behavior: contain; }

/* Numéros de téléphone : lisibles et appelables d'un appui. */
.bulle a.tel, .partage a.tel {
  text-decoration: underline;
  text-underline-offset: 2px;
  white-space: nowrap;
}

/* Lien secondaire de la page de partage (« Se connecter »). */
.partage-pied .lien-discret {
  color: var(--texte-doux, #9aa7b4);
  font-size: 0.9rem;
  text-decoration: underline;
  text-underline-offset: 2px;
}
