:root {
  --bg: #1b1b1f;
  --bg-2: #232328;
  --surface: #2d2d33;
  --surface-2: #3a3a42;
  --border: #44444d;
  --text: #ececf1;
  --muted: #a3a3ad;
  --accent: #7b83eb;
  --accent-2: #5b62c9;
  --danger: #e5484d;
  --danger-2: #c43237;
  --ok: #3fb950;
  --speaking: #7bd88f;
  --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 14px/1.45 "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
h1, h2, h3 { margin: 0; font-weight: 600; }
.muted { color: var(--muted); }
.error { color: #ff8589; min-height: 1.2em; }
.ic { width: 22px; height: 22px; fill: currentColor; flex: none; }

/* ---------- Formulaires & boutons ---------- */
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); }
input, select, textarea {
  font: inherit; color: var(--text); background: var(--bg-2);
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; width: 100%;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
button { font: inherit; color: inherit; cursor: pointer; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid var(--border); background: var(--surface); border-radius: 8px;
  padding: 8px 14px; font-weight: 500; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger:hover { background: var(--danger-2); }
.btn.small { padding: 5px 10px; font-size: 13px; }
.btn .ic { width: 18px; height: 18px; }
.btn:disabled { opacity: .5; cursor: default; }
.icon-btn {
  border: 0; background: transparent; border-radius: 8px; padding: 6px;
  display: inline-flex; align-items: center; justify-content: center; color: var(--muted);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Toasts ---------- */
#toasts { position: fixed; top: 16px; left: 50%; transform: translateX(-50%); z-index: 1000; display: grid; gap: 8px; pointer-events: none; }
.tile:fullscreen #toasts { top: 110px; } /* sous la barre de prise en main */
.toast {
  background: var(--surface-2); border: 1px solid var(--border); padding: 10px 16px; border-radius: 10px;
  box-shadow: 0 8px 24px #0008; max-width: min(520px, 92vw); transition: opacity .3s, transform .3s;
  overflow: hidden; text-overflow: ellipsis;
}
.toast.error { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }
.toast.out { opacity: 0; transform: translateY(-8px); }

/* ---------- Pages simples (accueil, admin) ---------- */
.page { max-width: 980px; margin: 0 auto; padding: 32px 20px; }
.brand { display: flex; align-items: center; gap: 10px; font-size: 18px; font-weight: 600; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--accent); display: grid; place-items: center; }
.brand .logo .ic { fill: #fff; }
.card { background: var(--bg-2); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.center-screen { min-height: 100%; display: grid; place-items: center; padding: 20px; text-align: center; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.grow { flex: 1; }
.stack { display: grid; gap: 14px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { color: var(--muted); font-weight: 500; font-size: 13px; }
code.link { background: var(--bg); padding: 3px 7px; border-radius: 6px; font-size: 12.5px; word-break: break-all; }
.badge { display: inline-block; background: var(--accent); color: #fff; border-radius: 99px; padding: 1px 8px; font-size: 12px; }
.badge.grey { background: var(--surface-2); color: var(--muted); }

/* ---------- Lobby ---------- */
#lobby { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.lobby-card { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(280px, 1fr); gap: 32px; width: min(1100px, 100%); align-items: center; }
.lobby-preview { position: relative; aspect-ratio: 16/9; background: #000; border-radius: 16px; overflow: hidden; }
.lobby-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.lobby-preview .avatar-wrap { position: absolute; inset: 0; display: grid; place-items: center; background: var(--surface); }
.preview-controls { position: absolute; bottom: 14px; left: 0; right: 0; display: flex; justify-content: center; gap: 12px; }
.meter { position: absolute; left: 16px; top: 16px; width: 90px; height: 6px; border-radius: 3px; background: #0007; overflow: hidden; }
.meter > div { height: 100%; width: 0; background: var(--speaking); transition: width .1s; }
.lobby-side { display: grid; gap: 14px; }
.lobby-side h1 { font-size: 26px; }
.sel-row { display: flex; gap: 6px; align-items: end; }
.sel-row label { flex: 1; }
@media (max-width: 820px) { .lobby-card { grid-template-columns: 1fr; } }

/* ---------- Avatars ---------- */
.avatar {
  width: 88px; height: 88px; border-radius: 50%; display: grid; place-items: center;
  font-size: 32px; font-weight: 600; color: #fff; user-select: none;
}
.avatar.sm { width: 34px; height: 34px; font-size: 13px; }

/* ---------- Réunion ---------- */
#meeting { height: 100%; display: grid; grid-template-rows: auto 1fr auto; }
.topbar { display: flex; align-items: center; gap: 12px; padding: 10px 16px; }
.topbar .title { font-weight: 600; font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar .clock { color: var(--muted); }
.main { display: flex; min-height: 0; padding: 0 12px; gap: 12px; }
.stage { flex: 1; min-width: 0; position: relative; display: flex; gap: 10px; }
.spotlight { display: none; }
.grid {
  flex: 1; display: flex; flex-wrap: wrap; justify-content: center; align-content: center; gap: 8px;
  --tile-w: 320px;
}
.grid > .tile { width: var(--tile-w); aspect-ratio: 16/9; }
.stage.presenting .spotlight { display: flex; flex: 1; min-width: 0; }
.stage.presenting .spotlight > .tile { flex: 1; }
.stage.presenting .grid {
  flex: 0 0 220px; flex-direction: column; flex-wrap: nowrap; justify-content: flex-start; overflow-y: auto;
}
.stage.presenting .grid > .tile { width: 100%; flex: none; }
@media (max-width: 760px) {
  /* Mobile en portrait : l'écran partagé prend juste sa hauteur (16/9), les vignettes en dessous sur deux colonnes */
  .stage.presenting { flex-direction: column; justify-content: center; }
  .stage.presenting .spotlight { flex: none; aspect-ratio: 16 / 9; max-height: 65%; }
  .stage.presenting .grid {
    flex: 0 1 auto; min-height: 90px; flex-direction: row; flex-wrap: wrap; align-content: flex-start; overflow-y: auto;
  }
  .stage.presenting .grid > .tile { width: calc(50% - 4px); }
}

.tile {
  position: relative; background: var(--surface); border-radius: var(--radius); overflow: hidden;
  outline: 3px solid transparent; outline-offset: -3px; transition: outline-color .15s; min-height: 0;
}
.tile.speaking { outline-color: var(--speaking); }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; opacity: 0; }
.tile.has-video video { opacity: 1; }
.tile.mirror video { transform: scaleX(-1); }
.tile-screen video { object-fit: contain; }
/* Zoom au pincement (écrans tactiles) : les gestes sur l'écran partagé sont gérés par la page */
.tile-screen video { touch-action: none; transform-origin: 0 0; }
.tile .avatar-wrap { position: absolute; inset: 0; display: grid; place-items: center; }
.tile.has-video .avatar-wrap { display: none; }
.tile-screen .avatar-wrap { display: none; }
.tile-label {
  position: absolute; left: 8px; bottom: 8px; display: flex; gap: 6px; align-items: center; max-width: calc(100% - 16px);
  background: #000a; padding: 3px 9px 3px 6px; border-radius: 6px; font-size: 13px;
}
.tile-label .ic { width: 16px; height: 16px; }
.tile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tile-mic { color: #ff8589; display: none; }
.tile.mic-off .tile-mic { display: inline-flex; }
.tile-hand { display: none; color: #ffd166; }
.tile.hand .tile-hand { display: inline-flex; }
.tile.hand { outline-color: #ffd166; }
.tile-actions { position: absolute; top: 6px; right: 6px; display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.tile:hover .tile-actions, .tile.pinned .tile-actions { opacity: 1; }
.tile-actions .icon-btn { background: #000a; color: #fff; }
.tile.pinned .act-pin { color: var(--accent); }
.tile-rc { position: absolute; top: 8px; left: 8px; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tile-rc .status { background: #000b; padding: 5px 10px; border-radius: 6px; font-size: 13px; }
.tile-rc .status.live { color: #ff8589; }
.tile-rc .rc-tab { opacity: .75; }
.tile-rc .rc-tab:hover { opacity: 1; }
/* Plein écran : barre centrée et éloignée du bord (certains navigateurs, comme Vivaldi, rognent le haut de la page) */
.tile:fullscreen .tile-rc { top: 56px; left: 50%; transform: translateX(-50%); flex-wrap: nowrap; padding: 6px; border-radius: 10px; background: #000a; }
.present-note { position: absolute; inset: 0; display: grid; place-content: center; gap: 12px; text-align: center; padding: 12px; background: var(--surface); }
.tile.controlling { outline-color: var(--danger); }
/* Pointeur local masqué : on suit le curseur de l'organisateur dans la vidéo (flèche hors de l'image) */
.tile.controlling video { cursor: none; }
.tile.controlling video.outside { cursor: default; }
.tile.controlling.show-cross video { cursor: crosshair; }
.tile.controlling .tile-label, .tile.controlling .tile-actions { pointer-events: none; opacity: .6; }
.tile:fullscreen { border-radius: 0; }
.tile:fullscreen video { object-fit: contain; }

/* ---------- Panneau latéral ---------- */
.side {
  width: 360px; flex: none; background: var(--bg-2); border-radius: var(--radius); display: flex; flex-direction: column; min-height: 0;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 8px 18px; }
.side-head h2 { font-size: 16px; }
.side-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
#messages { flex: 1; overflow-y: auto; padding: 4px 16px 10px; display: flex; flex-direction: column; gap: 12px; }
.msg { display: grid; gap: 3px; max-width: 92%; }
.msg-head { display: flex; gap: 8px; align-items: baseline; font-size: 12.5px; }
.msg-body { background: var(--surface); padding: 8px 12px; border-radius: 4px 12px 12px 12px; white-space: pre-wrap; word-break: break-word; }
.msg.mine { align-self: flex-end; }
.msg.mine .msg-head { justify-content: flex-end; }
.msg.mine .msg-body { background: var(--accent-2); border-radius: 12px 4px 12px 12px; }
.file-card {
  display: flex; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 8px 10px; text-decoration: none; color: var(--text);
}
.file-card:hover { border-color: var(--accent); }
.file-card .ic { width: 28px; height: 28px; color: var(--accent); }
.file-card .fname { font-weight: 500; word-break: break-all; }
.file-card .fsize { font-size: 12px; color: var(--muted); }
.file-thumb { max-width: 100%; max-height: 180px; border-radius: 8px; display: block; margin-top: 4px; }
.chat-empty { margin: auto; text-align: center; color: var(--muted); padding: 20px; }
#uploads { padding: 0 16px; display: grid; gap: 6px; }
.upload { display: grid; gap: 4px; font-size: 12.5px; color: var(--muted); }
.upload progress { width: 100%; height: 6px; accent-color: var(--accent); }
#chatForm { display: flex; gap: 6px; align-items: end; padding: 10px 12px 12px; position: relative; }
/* Mentions « @Nom » */
.mention { color: #b9bdff; font-weight: 600; }
.mention.me { background: #7b83eb40; color: #fff; border-radius: 4px; padding: 0 3px; }
.msg.mentioned .msg-body { box-shadow: inset 3px 0 0 var(--accent); }
.menu.mention-menu { position: absolute; left: 12px; right: 12px; bottom: calc(100% - 4px); min-width: 0; max-width: none; max-height: 280px; overflow-y: auto; }
.mention-menu .menu-item.active { background: var(--surface-2); }
#chatInput { resize: none; max-height: 120px; min-height: 40px; }
.side.dragover { outline: 2px dashed var(--accent); outline-offset: -6px; }

#peopleList { overflow-y: auto; padding: 0 8px; flex: 1; }
.person { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 8px; }
.person:hover { background: var(--surface); }
.person .pname { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.person .pname small { color: var(--muted); display: block; font-size: 12px; }
.person .ic { width: 18px; height: 18px; color: var(--muted); }
.person .ic.off { color: #ff8589; }
.person .ic.hand { color: #ffd166; }
.person-actions { display: flex; gap: 2px; }
.side-foot { padding: 12px 16px; border-top: 1px solid var(--border); }

/* ---------- Barre de contrôle ---------- */
.controls { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 12px 16px 16px; position: relative; }
.controls .group { display: flex; gap: 10px; align-items: center; }
.controls .right { position: absolute; right: 16px; }
.split { display: flex; align-items: center; background: var(--surface); border-radius: 26px; }
.split .round { background: transparent; }
.split .caret { border: 0; background: transparent; padding: 0 4px 0 2px; color: var(--muted); height: 48px; border-radius: 0 26px 26px 0; }
.split .caret:hover { color: var(--text); background: var(--surface-2); }
.split.off { background: var(--danger); }
.split.off .round, .split.off .caret { color: #fff; }
.round {
  width: 48px; height: 48px; border-radius: 50%; border: 0; display: inline-grid; place-items: center;
  background: var(--surface); color: var(--text); position: relative;
}
.round:hover { filter: brightness(1.15); }
.round.off { background: var(--danger); color: #fff; }
.round.active { background: var(--accent); color: #fff; }
.round.leave { width: 64px; border-radius: 24px; background: var(--danger); color: #fff; }
.round .count {
  position: absolute; top: -2px; right: -2px; background: var(--accent); color: #fff; font-size: 11px;
  min-width: 18px; height: 18px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px;
}
.round .count:empty { display: none; }
@media (max-width: 760px) {
  .controls .right { position: static; }
  .controls { flex-wrap: wrap; }
  .side { position: fixed; inset: 0; width: auto; z-index: 50; border-radius: 0; }
}
/* Petits écrans (téléphone en portrait ou en paysage) : barres plus compactes, rien ne déborde */
@media (max-width: 760px), (max-height: 500px) {
  .topbar { gap: 8px; padding: 8px 10px; }
  .topbar .clock { display: none; }
  .topbar .muted { white-space: nowrap; font-size: 13px; }
  #copyLinkBtn .label { display: none; }
  .main { padding: 0 8px; gap: 8px; }
  .controls { gap: 6px; padding: 8px 8px 10px; }
  .controls .group { gap: 6px; }
  .round { width: 44px; height: 44px; }
  .split .caret { height: 44px; }
  .round.leave { width: 56px; }
}
@media (max-height: 500px) and (min-width: 761px) {
  /* Téléphone en paysage : contrôles sur une seule ligne, vignettes plus étroites */
  .controls .right { position: static; }
  .stage.presenting .grid { flex-basis: 160px; }
}
/* Écrans tactiles (pas de survol) : boutons Épingler / Plein écran toujours visibles sur l'écran partagé */
@media (hover: none) {
  .tile-screen .tile-actions { opacity: 1; }
}

/* ---------- Menus ---------- */
.menu {
  position: fixed; z-index: 200; background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  box-shadow: 0 10px 30px #000a; padding: 6px; min-width: 260px; max-width: 360px;
}
.menu-title { font-size: 12px; color: var(--muted); padding: 8px 10px 4px; text-transform: uppercase; letter-spacing: .04em; }
.menu-item {
  display: flex; gap: 8px; align-items: center; width: 100%; text-align: left; border: 0; background: transparent;
  padding: 8px 10px; border-radius: 6px;
}
.menu-item:hover { background: var(--surface-2); }
.menu-item .ic { width: 18px; height: 18px; }
.menu-item .spacer { width: 18px; flex: none; }
.menu hr { border: 0; border-top: 1px solid var(--border); margin: 6px 0; }

/* ---------- Bandeau prise en main ---------- */
.rc-banner {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 100;
  background: var(--danger-2); color: #fff; padding: 8px 10px 8px 16px; border-radius: 10px;
  display: flex; gap: 14px; align-items: center; box-shadow: 0 8px 24px #000a;
}
.rc-banner .btn { background: #fff; color: var(--danger-2); border: 0; }

/* ---------- Dialogues ---------- */
dialog {
  background: var(--bg-2); color: var(--text); border: 1px solid var(--border); border-radius: 14px;
  padding: 24px; width: min(520px, 94vw); box-shadow: 0 20px 60px #000c;
}
dialog::backdrop { background: #000a; }
dialog h2 { font-size: 18px; margin-bottom: 12px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }
dialog ol { padding-left: 20px; display: grid; gap: 12px; }
.warn-box { background: #e5484d22; border: 1px solid #e5484d66; border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.install-box { background: #7b83eb1a; border: 1px solid #7b83eb66; border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; }
.install-box ol { margin: 10px 0 0; }
a.btn { text-decoration: none; }
.code-input { font-size: 22px; letter-spacing: .12em; text-align: center; font-variant-numeric: tabular-nums; }
.meeting-code { font-variant-numeric: tabular-nums; letter-spacing: .06em; font-weight: 600; }

/* ---------- Arrière-plan de la caméra ---------- */
.bg-dialog { width: min(680px, 96vw); }
.bg-preview { position: relative; aspect-ratio: 16/9; background: #000; border-radius: 10px; overflow: hidden; margin-bottom: 14px; }
.bg-preview video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); }
.bg-overlay { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; padding: 16px; background: #000a; color: var(--muted); }
.bg-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.bg-item {
  position: relative; aspect-ratio: 16/9; border: 2px solid transparent; border-radius: 8px; overflow: hidden; padding: 0;
  background: var(--surface); display: grid; place-items: center; color: var(--text);
}
.bg-item:hover { border-color: var(--border); }
.bg-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent) inset; }
.bg-item canvas, .bg-item img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.bg-item .bg-label {
  position: absolute; left: 0; right: 0; bottom: 0; font-size: 11.5px; padding: 2px 6px; background: #000a; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.bg-item .ic { width: 26px; height: 26px; margin-bottom: 14px; }
.bg-item .ic.light { opacity: .55; transform: scale(.8); }
