/* ---- Jetons ------------------------------------------------------- */
/* IMPORTANT : l'attribut `hidden` doit toujours masquer un élément, même si sa
 * classe définit un `display` (ex. .call en position fixe). Sans ce garde,
 * l'écran d'appel s'affiche par-dessus tout au démarrage et bloque l'interface. */
[hidden] { display: none !important; }

:root {
  --deep:      #0a1d24;   /* eau profonde, fond          */
  --deep-2:    #0c232b;   /* fond app                    */
  --surface:   #123039;   /* bulles reçues, cartes       */
  --surface-2: #163b46;   /* survols                     */
  --line:      #1f4a56;   /* filets                      */
  --ink:       #eaf3f2;   /* texte principal             */
  --muted:     #7fa3a8;   /* texte secondaire            */
  --signal:    #5fd6bd;   /* la connexion, le vivant     */
  --beacon:    #e6a15c;   /* soi, la balise, l'appel     */
  --danger:    #e0685f;
  --radius:    16px;
  --mono: ui-monospace, "SF Mono", "JetBrains Mono", "Roboto Mono", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--sans);
  background: var(--deep-2);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  overscroll-behavior: none;
}
button { font-family: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--signal); outline-offset: 2px; border-radius: 6px; }

/* ---- Écran d'accueil ---------------------------------------------- */
.onboarding {
  position: fixed; inset: 0; display: grid; place-items: center;
  padding: 24px; background:
    radial-gradient(120% 80% at 50% -10%, #123039 0%, var(--deep) 70%);
}
.onboarding__card {
  width: 100%; max-width: 400px;
  background: rgba(18, 48, 57, 0.6);
  border: 1px solid var(--line);
  border-radius: 22px; padding: 28px;
  backdrop-filter: blur(8px);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand__word {
  font-size: 26px; font-weight: 700; letter-spacing: -0.02em;
}
.onboarding__lede { color: var(--muted); line-height: 1.5; margin: 14px 0 22px; }
.field { display: block; margin-bottom: 18px; }
.field__label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 7px; }
.field input {
  width: 100%; padding: 13px 14px;
  background: var(--deep); color: var(--ink);
  border: 1px solid var(--line); border-radius: 12px; font-size: 16px;
}
.field input::placeholder { color: #4d6f76; }
.field__hint { display: block; font-size: 12px; color: var(--muted); margin-top: 7px; line-height: 1.45; }
.check {
  display: flex; gap: 10px; align-items: flex-start;
  font-size: 13px; color: var(--muted); margin: 4px 0 22px; line-height: 1.4;
}
.check input { margin-top: 2px; accent-color: var(--signal); }
.onboarding__error { color: var(--danger); font-size: 13px; margin-top: 12px; }

.btn {
  border: none; border-radius: 12px; font-size: 15px; font-weight: 600;
  padding: 13px 18px; transition: transform .06s ease, background .15s ease;
}
.btn:active { transform: translateY(1px); }
.btn--primary { width: 100%; background: var(--signal); color: #06232a; }
.btn--primary:hover { background: #74e2ca; }
.btn--ghost {
  background: transparent; color: var(--ink);
  border: 1px solid var(--line); padding: 8px 14px; font-size: 14px;
}
.btn--ghost:hover { background: var(--surface-2); }

/* ---- Coquille app ------------------------------------------------- */
.app {
  display: flex; flex-direction: column; height: 100dvh;
  max-width: 720px; margin: 0 auto; background: var(--deep-2);
}
.main { display: flex; flex-direction: column; flex: 1; min-height: 0; min-width: 0; }
.sidebar { display: none; }  /* apparaît en disposition bureau (voir @media) */
.topbar__logo { display: inline; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); gap: 12px;
}
.topbar__left { display: flex; align-items: center; gap: 12px; min-width: 0; }
.rooms { display: flex; align-items: center; gap: 6px; min-width: 0; }
.rooms__select {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px;
  padding: 7px 10px; font-size: 15px; font-weight: 600; max-width: 46vw;
}
.rooms__add {
  width: 32px; height: 32px; border-radius: 10px;
  background: var(--surface); color: var(--signal);
  border: 1px solid var(--line); font-size: 18px; line-height: 1;
}

/* ---- Signature : la ligne d'ancre --------------------------------- */
.anchor {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 16px; font-family: var(--mono); font-size: 12px;
  color: var(--muted); border-bottom: 1px solid var(--line);
  background: linear-gradient(var(--deep), var(--deep-2));
}
.anchor__dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--muted);
  flex: none; box-shadow: 0 0 0 0 transparent;
}
.anchor__tether {
  flex: none; width: 26px; height: 1px; background:
    repeating-linear-gradient(90deg, var(--line) 0 4px, transparent 4px 8px);
}
.anchor__text { letter-spacing: 0.02em; }
.anchor__peers { margin-left: auto; color: var(--signal); }
.anchor[data-state="online"] .anchor__dot {
  background: var(--signal); animation: pulse 2.4s ease-in-out infinite;
}
.anchor[data-state="online"] .anchor__tether {
  background: repeating-linear-gradient(90deg, var(--signal) 0 4px, transparent 4px 8px);
  animation: flow 1s linear infinite;
}
.anchor[data-state="offline"] .anchor__text { color: var(--beacon); }
@keyframes pulse { 0%,100%{ box-shadow:0 0 0 0 rgba(95,214,189,.5);} 50%{ box-shadow:0 0 0 5px rgba(95,214,189,0);} }
@keyframes flow { to { background-position: 8px 0; } }

/* ---- Messages ----------------------------------------------------- */
.messages {
  list-style: none; margin: 0; padding: 16px 14px 8px;
  flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px;
}
.msg { max-width: 78%; display: flex; flex-direction: column; }
.msg--mine { align-self: flex-end; align-items: flex-end; }
.msg__meta {
  font-size: 11px; color: var(--muted); margin: 8px 4px 3px;
  font-family: var(--mono);
}
.msg--mine .msg__meta { display: none; }
.msg__bubble {
  background: var(--surface); padding: 9px 13px;
  border-radius: 15px 15px 15px 4px; line-height: 1.45;
  word-wrap: break-word; overflow-wrap: anywhere; position: relative;
}
.msg--mine .msg__bubble {
  background: color-mix(in srgb, var(--beacon) 22%, var(--surface));
  border-radius: 15px 15px 4px 15px;
}
.msg--consecutive { margin-top: 0; }
.msg__bubble img {
  max-width: 100%; border-radius: 10px; display: block; margin: 2px 0; cursor: pointer;
}
.msg__file {
  display: flex; align-items: center; gap: 10px;
  color: var(--signal); text-decoration: none; font-size: 14px;
}
.filecard { display: flex; flex-direction: column; gap: 8px; min-width: 210px; }
.filecard__info { display: flex; flex-direction: column; gap: 2px; }
.filecard__name { font-size: 14px; word-break: break-word; }
.filecard__meta { font-size: 11px; color: var(--muted); font-family: var(--mono); }
.filecard__actions { display: flex; gap: 8px; }
.filecard__btn {
  background: var(--surface-2); border: 1px solid var(--line); color: var(--signal);
  border-radius: 10px; padding: 5px 10px; font-size: 12px; cursor: pointer;
}
.filecard__btn:hover { background: var(--deep); }
.msg__time { font-size: 10px; color: var(--muted); font-family: var(--mono); margin: 3px 4px 0; }
.msg__reactions { display: flex; gap: 4px; flex-wrap: wrap; margin: 4px 2px 0; }
.msg__reaction {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 20px; padding: 1px 8px; font-size: 12px; color: var(--ink); cursor: pointer;
}
.msg__reaction--mine { border-color: var(--signal); background: color-mix(in srgb, var(--signal) 18%, var(--surface-2)); }
.day-sep {
  align-self: center; font-family: var(--mono); font-size: 11px;
  color: var(--muted); margin: 14px 0 6px;
}

/* ---- Réactions contextuelles -------------------------------------- */
.reactions {
  position: fixed; display: flex; gap: 2px; z-index: 5;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 26px; padding: 5px 7px; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.reactions button { background: none; border: none; font-size: 20px; padding: 3px 4px; border-radius: 50%; }
.reactions button:hover { background: var(--surface); }

/* ---- Composeur ---------------------------------------------------- */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 10px 12px; padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--deep-2);
}
.composer__icon, .composer__send {
  flex: none; width: 40px; height: 40px; border-radius: 50%;
  border: none; font-size: 20px; line-height: 1;
}
.composer__icon { background: var(--surface); color: var(--signal); }
.composer__send { background: var(--signal); color: #06232a; font-weight: 700; }
.composer__text {
  flex: 1; resize: none; max-height: 120px;
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 20px;
  padding: 10px 14px; font-size: 16px; font-family: inherit; line-height: 1.4;
}
.composer__text::placeholder { color: #4d6f76; }

/* ---- Appel de groupe ---------------------------------------------- */
.call { position: fixed; inset: 0; background: #05161b; z-index: 40; display: flex; flex-direction: column; }
.call__grid {
  flex: 1; display: grid; gap: 6px; padding: 6px;
  padding-top: max(6px, env(safe-area-inset-top));
  grid-template-columns: 1fr; align-content: stretch;
}
/* La grille s'adapte au nombre de participants. */
.call__grid[data-count="2"] { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
.call__grid[data-count="3"], .call__grid[data-count="4"] { grid-template-columns: 1fr 1fr; }
.call__grid[data-count="5"], .call__grid[data-count="6"] { grid-template-columns: 1fr 1fr; grid-auto-rows: 1fr; }
.tile { position: relative; background: var(--surface); border-radius: 12px; overflow: hidden; min-height: 0; }
.tile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.tile__name {
  position: absolute; left: 8px; bottom: 8px;
  font-family: var(--mono); font-size: 11px; color: var(--ink);
  background: rgba(5,22,27,.6); padding: 2px 8px; border-radius: 8px;
}
.tile--muted::after {
  content: "micro coupé"; position: absolute; right: 8px; bottom: 8px;
  font-family: var(--mono); font-size: 10px; color: var(--beacon);
  background: rgba(5,22,27,.6); padding: 2px 6px; border-radius: 8px;
}
.call__status {
  position: absolute; top: max(14px, env(safe-area-inset-top)); left: 0; right: 0;
  text-align: center; font-family: var(--mono); font-size: 13px; color: var(--signal);
  pointer-events: none;
}
.call__controls {
  display: flex; justify-content: center; gap: 12px;
  padding: 18px; padding-bottom: max(18px, env(safe-area-inset-bottom));
}
.call__ctrl {
  padding: 12px 18px; border-radius: 30px; border: 1px solid var(--line);
  background: var(--surface); color: var(--ink); font-size: 14px; font-weight: 600;
}
.call__ctrl--end { background: var(--danger); border-color: var(--danger); color: #2a0a08; }
.call__ctrl[data-off="true"] { opacity: .5; }

/* ---- Invitation entrante ------------------------------------------ */
.incoming { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center;
  background: rgba(5,22,27,.86); backdrop-filter: blur(6px); padding: 24px; }
.incoming__card { text-align: center; }
.incoming__ring {
  width: 84px; height: 84px; border-radius: 50%; margin: 0 auto 20px;
  border: 3px solid var(--signal);
  animation: ring 1.4s ease-in-out infinite;
}
@keyframes ring { 0%,100%{ box-shadow:0 0 0 0 rgba(95,214,189,.5);} 50%{ box-shadow:0 0 0 18px rgba(95,214,189,0);} }
.incoming__text { font-size: 18px; margin-bottom: 26px; }
.incoming__buttons { display: flex; gap: 12px; justify-content: center; }
.incoming__buttons .btn { min-width: 130px; }
.call__ctrl--end.btn { color: #2a0a08; }

/* ---- Feuille (panneau sauvegarde) --------------------------------- */
.sheet {
  position: fixed; inset: 0; z-index: 45; display: flex; align-items: flex-end;
  background: rgba(5,22,27,.7); backdrop-filter: blur(4px);
}
.sheet__card {
  width: 100%; max-width: 720px; margin: 0 auto;
  background: var(--deep-2); border-top: 1px solid var(--line);
  border-radius: 22px 22px 0 0; padding: 20px 20px max(24px, env(safe-area-inset-bottom));
  animation: rise .18s ease;
}
@keyframes rise { from { transform: translateY(20px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet__head { display: flex; align-items: center; justify-content: space-between; }
.sheet__title { font-size: 18px; margin: 0; }
.sheet__close { background: none; border: none; color: var(--muted); font-size: 18px; }
.sheet__lede { color: var(--muted); line-height: 1.5; font-size: 14px; margin: 10px 0 16px; }
.sheet__lede strong { color: var(--signal); }
.sheet__status {
  font-family: var(--mono); font-size: 13px; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; line-height: 1.6;
}
.sheet__status .ok { color: var(--signal); }
.sheet__status .warn { color: var(--beacon); }
.sheet .btn--primary { width: 100%; margin-bottom: 10px; }
.sheet__wide { width: 100%; }
.sheet__note { font-size: 12px; color: var(--muted); margin-top: 16px; line-height: 1.5; }

.members__h { font-size: 13px; color: var(--muted); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .04em; }
.members__list { list-style: none; display: flex; flex-direction: column; gap: 6px; }
.members__item {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 9px 12px;
}
.members__name { display: flex; align-items: center; gap: 9px; font-size: 14px; }
.members__dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex: none; }
.members__dot.on { background: var(--signal); box-shadow: 0 0 6px var(--signal); }
.members__empty { color: var(--muted); font-size: 13px; padding: 4px 2px; }
.members__remove {
  background: transparent; border: 1px solid var(--line); color: var(--beacon);
  border-radius: 8px; width: 28px; height: 28px; cursor: pointer; font-size: 13px;
}
.members__remove:hover { border-color: var(--beacon); }
.members__add {
  background: var(--signal); border: none; color: #06231f;
  border-radius: 9px; padding: 6px 12px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.members__add:disabled { opacity: .45; cursor: default; }
.toast {
  position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%);
  background: var(--surface-2); border: 1px solid var(--line);
  color: var(--ink); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; z-index: 60; max-width: 90vw; text-align: center;
}

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; }
}

/* ====================================================================
 *  DISPOSITION BUREAU (grand écran) : barre latérale + volet principal
 * ================================================================== */
@media (min-width: 900px) {
  .app {
    flex-direction: row; max-width: 1160px; height: 100dvh;
    border-left: 1px solid var(--line); border-right: 1px solid var(--line);
  }
  .sidebar {
    display: flex; flex-direction: column; width: 264px; flex: none;
    border-right: 1px solid var(--line); padding: 14px 12px;
    background: linear-gradient(var(--deep), var(--deep-2));
  }
  .sidebar__brand {
    display: flex; align-items: center; gap: 10px;
    font-size: 18px; font-weight: 700; letter-spacing: .02em;
    padding: 6px 8px 14px; color: var(--ink);
  }
  .sidebar__spacer { flex: 1; }
  .rail { display: flex; flex-direction: column; gap: 4px; overflow-y: auto; }
  .rail__item {
    text-align: left; background: transparent; border: 1px solid transparent;
    color: var(--ink); border-radius: 10px; padding: 10px 12px; font-size: 15px;
    cursor: pointer; display: flex; align-items: center; gap: 9px;
  }
  .rail__item:hover { background: var(--surface); }
  .rail__item--on { background: var(--surface-2); border-color: var(--line); font-weight: 600; }
  .rail__add {
    margin-top: 8px; background: var(--surface); color: var(--signal);
    border: 1px solid var(--line); border-radius: 10px; padding: 9px 12px;
    font-size: 14px; cursor: pointer; text-align: left;
  }
  .rail__link {
    background: transparent; color: var(--muted); border: 1px solid var(--line);
    border-radius: 10px; padding: 9px 12px; font-size: 13px; cursor: pointer;
  }
  .rail__link:hover { color: var(--signal); border-color: var(--signal); }
  /* Sur grand écran, la navigation des groupes passe dans la barre latérale. */
  .topbar .rooms { display: none; }
  .topbar__logo { display: none; }
  .messages { padding: 20px 22px 10px; }
  .msg { max-width: 68%; }
}
.rail__link { display: none; }
@media (min-width: 900px) { .rail__link { display: block; } }

/* ====================================================================
 *  LIAISON D'APPAREIL (QR + code)
 * ================================================================== */
.link__tabs { display: flex; gap: 8px; margin: 4px 0 14px; }
.link__tab {
  flex: 1; background: var(--surface); color: var(--muted);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px; font-size: 14px; cursor: pointer;
}
.link__tab--on { color: var(--ink); border-color: var(--signal); background: var(--surface-2); }
.qr {
  display: flex; align-items: center; justify-content: center;
  background: #fff; border-radius: 14px; padding: 16px; margin: 6px auto 0;
  width: max-content; max-width: 100%;
}
.qr svg { display: block; width: 232px; height: 232px; }
.link__code {
  font-family: var(--mono); font-size: 12px; word-break: break-all;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; color: var(--signal); margin-bottom: 12px;
  user-select: all; -webkit-user-select: all;
}
.link__input {
  width: 100%; background: var(--surface); color: var(--ink);
  border: 1px solid var(--line); border-radius: 10px; padding: 12px;
  font-family: var(--mono); font-size: 13px; margin-bottom: 12px;
}
.onboarding__link {
  display: block; width: 100%; margin-top: 14px; background: transparent;
  border: none; color: var(--muted); font-size: 13px; text-decoration: underline; cursor: pointer;
}
.onboarding__link:hover { color: var(--signal); }

/* ---- Contacts ----------------------------------------------------- */
.ct-searchrow { display: flex; gap: 8px; align-items: center; }
.ct-searchrow .link__input { flex: 1; }
.ct-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.btn--small { padding: 5px 9px; font-size: 12px; }
.ct-badge {
  font-size: 10px; font-weight: 700; color: var(--deep-2); background: var(--signal);
  border-radius: 6px; padding: 1px 6px; margin-left: 6px; vertical-align: middle;
}
.ct-fp {
  font-family: var(--mono); font-size: 12px; color: var(--muted);
  text-align: center; margin-top: 10px; letter-spacing: 0.04em;
}
.members__meta { font-family: var(--mono); font-size: 11px; color: var(--muted); }
/* L'icône Contacts de la barre du haut disparaît en disposition bureau
   (la barre latérale a son propre bouton). */
@media (min-width: 900px) { #btn-contacts-open, #btn-notif { display: none; } }

/* ---- Conversations dans la barre latérale ------------------------- */
.rail__sep {
  font-size: 11px; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); padding: 12px 12px 4px; margin-top: 6px;
  border-top: 1px solid var(--line);
}
.ct-groupbar { margin-bottom: 10px; }
.ct-groupbar__actions { display: flex; gap: 8px; }
.ct-check { display: flex; align-items: center; gap: 10px; cursor: pointer; width: 100%; }
.ct-check input { width: 18px; height: 18px; accent-color: var(--signal); }
