/* Salle de visioconférence — plein écran, posée sur l'application. */

.salle {
  position: fixed; inset: 0; z-index: 200;
  display: flex; flex-direction: column;
  background: var(--bg-deep); color: var(--text);
  /* 100dvh : sur iPhone, 100vh passe sous la barre d'adresse. */
  height: 100dvh;
}

.salle-tete {
  flex: none; display: flex; align-items: center; gap: 10px;
  padding: 10px var(--gutter); padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: var(--bg);
}
.salle-tete h2 { flex: 1; margin: 0; font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.salle-etat { font-size: 12px; color: var(--text-dim); }

.salle-scene { flex: 1; min-height: 0; position: relative; display: flex; flex-direction: column; }

/* ------------------------------------------------------------ vignettes */
.salle-tuiles {
  flex: 1; min-height: 0; display: grid; gap: 8px; padding: 8px;
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 220px), 1fr));
  grid-auto-rows: 1fr; overflow-y: auto;
}
.tuile {
  position: relative; overflow: hidden; border-radius: var(--radius);
  background: var(--surface); border: 1px solid var(--line);
  min-height: 120px; display: flex; align-items: center; justify-content: center;
}
.tuile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tuile.moi video { transform: scaleX(-1); }
.tuile.sans-image video { visibility: hidden; }
.tuile-initiale {
  width: 64px; height: 64px; border-radius: 50%; display: none;
  align-items: center; justify-content: center; font-size: 26px; font-weight: 600;
  background: var(--accent-dim); color: var(--accent-soft);
}
.tuile.sans-image .tuile-initiale { display: flex; }
.tuile-nom {
  position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px);
  padding: 3px 9px; border-radius: 999px; font-size: 12px;
  background: rgba(5, 13, 22, .72); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.tuile-main {
  position: absolute; top: 8px; right: 8px; display: none; padding: 4px 9px;
  border-radius: 999px; background: var(--warn); color: #231a00; font-size: 14px; border: 0;
}
.tuile.main .tuile-main { display: block; }
.tuile.muet .tuile-nom::after { content: " · micro coupé"; color: var(--text-faint); }

/* ------------------------------------------------- scène principale */
.salle-grand { flex: 1; min-height: 0; position: relative; background: #000; display: none; }
.salle-grand video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.salle-grand iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: #fff; }
.salle.avec-grand .salle-grand { display: block; }

/* Partage d'écran : le grand écran en haut, les vignettes en bande dessous. */
.salle.avec-grand .salle-tuiles {
  flex: none; height: 112px; grid-auto-flow: column; grid-auto-columns: 150px;
  grid-template-columns: none; grid-auto-rows: 100%; overflow-x: auto; overflow-y: hidden;
}
.salle.avec-grand .tuile { min-height: 0; }

/* Tableau, côté élève : les vignettes se rangent d'emblée, et reviennent en encart. */

/* Tableau, côté prof : les vignettes passent dans un encart réductible. */
.salle.tableau-prof .salle-tuiles,
.salle.tableau-eleve .salle-tuiles {
  position: absolute; right: 10px; bottom: 10px; z-index: 5; width: min(260px, 60vw);
  height: auto; max-height: 55%; display: grid; grid-auto-flow: row; grid-auto-columns: auto;
  grid-template-columns: 1fr; grid-auto-rows: 120px; overflow-y: auto;
  padding: 8px; border-radius: var(--radius); background: rgba(8, 21, 34, .88);
  border: 1px solid var(--line); box-shadow: var(--shadow);
}
.salle.tableau-prof.encart-ferme .salle-tuiles,
.salle.tableau-eleve.encart-ferme .salle-tuiles { display: none; }
/* Le bouton qui réduit les caméras : un libellé, pas une icône — l'icône seule
   ne disait pas à quoi elle servait. */
.salle-pilule {
  flex: none; height: 34px; padding: 0 12px; border-radius: 17px 0 0 17px;
  border: 1px solid var(--line); border-right: 0;
  background: var(--surface-2); color: var(--text); font-size: 12.5px; cursor: pointer; white-space: nowrap;
}
.salle.avec-grand.encart-ferme .salle-tuiles { display: none; }

/* Barre cachée d'un toucher sur l'image : toute la place pour le tableau. */
.salle.barre-cachee .salle-barre,
.salle.barre-cachee .salle-tete { display: none; }

/* --------------------------------------------------------- barre d'outils */
.salle-barre {
  flex: none; display: flex; align-items: center; gap: 8px;
  /* Pas de marge à droite : le bouton des caméras touche le bord de l'écran. */
  padding: 10px 0 10px var(--gutter); padding-bottom: max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line); background: var(--bg);
}
.salle-barre-centre { flex: 1; display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.salle-bouton {
  position: relative; width: 48px; height: 48px; border-radius: 50%; border: 1px solid var(--line);
  background: var(--surface-2); color: var(--text); display: flex; align-items: center;
  justify-content: center; cursor: pointer; font-size: 20px;
}
.salle-bouton:hover { background: var(--surface); }
.salle-bouton.coupe { background: var(--danger); border-color: var(--danger); }
.salle-bouton.actif { background: var(--accent); border-color: var(--accent); }
.salle-bouton.quitter { background: var(--danger); border-color: var(--danger); width: auto; border-radius: 24px; padding: 0 18px; font-size: 14px; gap: 8px; }
.salle-bouton[hidden] { display: none; }
.salle-pastille {
  position: absolute; top: -4px; right: -4px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); font-size: 11px; line-height: 18px; text-align: center;
}

/* ------------------------------------------------------------------ tchat */
.salle-tchat {
  position: absolute; top: 0; right: 0; bottom: 0; z-index: 10; width: min(340px, 100%);
  display: none; flex-direction: column; background: var(--bg); border-left: 1px solid var(--line);
}
.salle.tchat-ouvert .salle-tchat { display: flex; }
.salle-tchat-liste { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 8px; }
.salle-msg { max-width: 88%; padding: 7px 11px; border-radius: 12px; background: var(--surface-2); font-size: 14px; word-break: break-word; }
.salle-msg b { display: block; font-size: 11px; color: var(--text-dim); font-weight: 500; }
.salle-msg.moi { align-self: flex-end; background: var(--accent-dim); }
.salle-tchat-saisie { flex: none; display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); }
.salle-tchat-saisie input {
  flex: 1; min-width: 0; height: 42px; border-radius: 21px; padding: 0 14px;
  border: 1px solid var(--line); background: var(--surface); color: var(--text); font: inherit;
  /* 16 px : en dessous, Safari zoome la page à la prise de focus. */
  font-size: 16px;
}

.salle-accueil { margin: auto; text-align: center; padding: 24px; color: var(--text-dim); }

/* Lecture refusée par le navigateur : un bouton bien visible pour la relancer. */
.salle-son {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 12;
  height: 44px; padding: 0 20px; border-radius: 22px; border: 0; cursor: pointer;
  background: var(--accent); color: #fff; font-size: 15px; box-shadow: var(--shadow);
}
.salle-son[hidden] { display: none; }

/* Secours pour iPhone : la salle couchée par une rotation de 90°, quand ni le
   plein écran ni le verrouillage de l'orientation ne sont possibles. */
.salle.paysage-force {
  inset: auto; top: 0; left: 0;
  width: 100dvh; height: 100dvw;
  transform-origin: top left;
  transform: translateX(100dvw) rotate(90deg);
}

/* Le prof retire un invité sans compte qu'il ne reconnaît pas (bouton sur sa vignette). */
.tuile-retirer {
  position: absolute; left: 6px; top: 6px; z-index: 3;
  padding: 4px 9px; border: 0; border-radius: 999px; cursor: pointer;
  background: rgba(240, 138, 36, .92); color: #fff; font-size: 12px; font-weight: 600;
}
.tuile-retirer:hover { background: #f08a24; }
