:root {
  --bg: #eef0f6; --panel: #ffffff; --panel-2: #f1f3f8; --text: #11142a; --muted: #6b7189; --line: #e4e7f0;
  --accent: #6366f1; --accent-2: #22d3ee; --danger: #e5484d;
  --bubble-in: #ffffff; --bubble-out: linear-gradient(135deg, #6366f1, #5b6cf0 60%, #4f8ff0);
  --chat-bg: #e7eaf4; --shadow: 0 1px 2px rgba(17, 20, 42, .08);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d14; --panel: #131622; --panel-2: #1b1f2e; --text: #e8eaf3; --muted: #8a90a8; --line: #232839;
    --bubble-in: #1d2232; --chat-bg: #0e1119; --shadow: 0 1px 2px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; margin: 0; }
html, body { height: 100%; }
body {
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; overflow: hidden;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
input, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }
svg { width: 22px; height: 22px; flex: none; }
.muted { color: var(--muted); }
.opt { color: var(--muted); font-weight: 400; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---------- Champs & boutons ---------- */
.field {
  width: 100%; padding: 11px 13px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--panel-2); outline: none; transition: border-color .15s, box-shadow .15s; resize: vertical;
}
.field:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }
label { display: grid; gap: 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
label.check { display: flex; align-items: flex-start; gap: 10px; color: var(--text); font-size: 14px; font-weight: 400; }
label.check input { width: 18px; height: 18px; accent-color: var(--accent); margin-top: 1px; flex: none; }
.btn {
  padding: 10px 18px; border-radius: 12px; font-weight: 600; color: #fff;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 65%, var(--accent-2)));
  transition: filter .15s, transform .1s;
}
.btn:hover { filter: brightness(1.08); }
.btn:active { transform: scale(.98); }
.btn.big { padding: 13px; font-size: 16px; }
.btn.danger { background: var(--danger); }
.ghost { padding: 10px 16px; border-radius: 12px; color: var(--accent); font-weight: 600; display: inline-flex; gap: 8px; align-items: center; }
.ghost:hover { background: var(--panel-2); }
.ghost.danger { color: var(--danger); }
.ghost svg { width: 18px; height: 18px; }
.icon { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; transition: background .15s; }
.icon:hover { background: var(--panel-2); color: var(--text); }
.error { color: var(--danger); font-size: 13px; }
.error:empty { display: none; }

/* ---------- Connexion ---------- */
#auth {
  height: 100dvh; overflow-y: auto; display: grid; place-items: center; padding: 24px 16px;
  background:
    radial-gradient(900px 500px at 0% 0%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 70%),
    radial-gradient(800px 500px at 100% 100%, color-mix(in srgb, var(--accent-2) 22%, transparent), transparent 70%),
    var(--bg);
}
.card {
  width: 100%; max-width: 400px; background: var(--panel); border: 1px solid var(--line); border-radius: 24px;
  padding: 30px 26px; display: grid; gap: 16px; box-shadow: 0 24px 70px rgba(20, 24, 60, .18);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand img { width: 44px; height: 44px; }
.brand h1 { font-size: 28px; letter-spacing: -.03em; }
.tabs { display: grid; grid-template-columns: 1fr 1fr; background: var(--panel-2); border-radius: 12px; padding: 4px; }
.tabs button { padding: 9px; border-radius: 9px; color: var(--muted); font-weight: 600; transition: background .15s; }
.tabs .on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.card:not(.register) .reg { display: none; }

/* ---------- Disposition ---------- */
#app { height: 100dvh; display: grid; grid-template-columns: minmax(300px, 380px) 1fr; }
#side { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; position: relative; }
.side-head { display: flex; gap: 8px; align-items: center; padding: 12px; padding-top: max(12px, env(safe-area-inset-top)); }
#search {
  flex: 1; min-width: 0; padding: 10px 16px; border-radius: 999px; border: 1px solid transparent;
  background: var(--panel-2); outline: none; transition: border-color .15s;
}
#search:focus { border-color: var(--accent); }

.list { list-style: none; padding: 0 8px 96px; overflow-y: auto; flex: 1; }
.item { display: flex; gap: 12px; align-items: center; padding: 9px 10px; border-radius: 14px; cursor: pointer; transition: background .12s; }
.item:hover { background: var(--panel-2); }
.item.on { background: var(--accent); color: #fff; }
.item.on .preview, .item.on .time { color: rgba(255, 255, 255, .82); }
.meta { flex: 1; min-width: 0; }
.row { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 6px; align-items: center; }
.title svg { width: 15px; height: 15px; opacity: .7; }
.title.secret { color: #16a34a; }
.title.secret svg { opacity: 1; }
.item.on .title.secret { color: #fff; }
@media (prefers-color-scheme: dark) { .title.secret { color: #4ade80; } }
.pad { padding: 10px 12px; }
/* Partenaires */
.partner {
  display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 50%; margin-left: 4px; flex: none;
  background: linear-gradient(135deg, #fcd34d, #f59e0b); color: #fff; font-size: 10px; font-weight: 800; vertical-align: 1px;
}
.gold { color: #d97706; }
@media (prefers-color-scheme: dark) { .gold { color: #fbbf24; } }
.msg .from.gold { color: #d97706; }
@media (prefers-color-scheme: dark) { .msg .from.gold { color: #fbbf24; } }
.item.on .gold { color: #fff; }
.av.gold { box-shadow: 0 0 0 2px var(--panel), 0 0 0 4px #f59e0b; }
.tag.star { background: color-mix(in srgb, #f59e0b 18%, transparent); color: #b45309; }
@media (prefers-color-scheme: dark) { .tag.star { color: #fbbf24; } }
.online { display: flex; align-items: center; gap: 6px; padding: 0 20px 8px; font-size: 13px; color: var(--muted); }
.online i { width: 8px; height: 8px; border-radius: 50%; background: #22c55e; box-shadow: 0 0 0 3px color-mix(in srgb, #22c55e 25%, transparent); }
.online span { font-weight: 700; color: var(--text); }
.role-btns { display: flex; flex-wrap: wrap; gap: 4px; }
.role-btns .ghost { padding: 8px 12px; background: var(--panel-2); }
.big-num { font-size: 40px; font-weight: 800; letter-spacing: -.02em; }
.fp { display: grid; gap: 6px; text-align: center; background: var(--panel-2); border-radius: 14px; padding: 14px; }
.fp .emoji { font-size: 26px; letter-spacing: 4px; line-height: 1.3; }
.preview { color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.time { font-size: 12px; color: var(--muted); flex: none; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 12px; font-weight: 700; padding: 1px 7px; min-width: 21px; text-align: center; flex: none; }
.item.on .badge { background: #fff; color: var(--accent); }
.tag { font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--panel-2); color: var(--muted); flex: none; }
.section-title { padding: 14px 12px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; list-style: none; }
.hint { padding: 32px 20px; text-align: center; color: var(--muted); list-style: none; }

.av {
  width: 50px; height: 50px; border-radius: 50%; display: grid; place-items: center; color: #fff;
  font-weight: 600; flex: none; font-size: 17px; background: var(--c); letter-spacing: .02em;
}
.av.sm { width: 40px; height: 40px; font-size: 15px; }
.av.big { width: 88px; height: 88px; font-size: 32px; }

.fab {
  position: absolute; right: 20px; bottom: max(20px, env(safe-area-inset-bottom)); width: 58px; height: 58px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
  color: #fff; display: grid; place-items: center;
  box-shadow: 0 10px 28px color-mix(in srgb, var(--accent) 45%, transparent); transition: transform .15s;
}
.fab:hover { transform: scale(1.06); }

/* ---------- Menu flottant ---------- */
.menu {
  position: fixed; z-index: 50; background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 16px 48px rgba(10, 12, 30, .25); padding: 6px; min-width: 230px; animation: pop .14s ease-out;
}
.menu .me { padding: 10px 12px 12px; border-bottom: 1px solid var(--line); margin-bottom: 6px; }
.menu .me b { display: block; }
.menu button { display: flex; gap: 12px; align-items: center; width: 100%; padding: 10px 12px; border-radius: 10px; text-align: left; }
.menu button:hover { background: var(--panel-2); }
.menu button svg { width: 19px; height: 19px; color: var(--muted); }
.menu .danger, .menu .danger svg { color: var(--danger); }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }

/* ---------- Discussion ---------- */
#chat {
  display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative;
  background:
    radial-gradient(700px 400px at 100% 0%, color-mix(in srgb, var(--accent) 10%, transparent), transparent 70%),
    radial-gradient(600px 400px at 0% 100%, color-mix(in srgb, var(--accent-2) 8%, transparent), transparent 70%),
    var(--chat-bg);
}
.empty { margin: auto; display: grid; justify-items: center; gap: 14px; color: var(--muted); padding: 20px; text-align: center; }
.empty img { width: 72px; opacity: .9; }
.chat-head {
  display: flex; align-items: center; gap: 8px; padding: 8px 12px; padding-top: max(8px, env(safe-area-inset-top));
  background: var(--panel); border-bottom: 1px solid var(--line);
}
.who { flex: 1; min-width: 0; display: flex; gap: 12px; align-items: center; text-align: left; padding: 4px; border-radius: 12px; }
.who .meta div:last-child { font-size: 13px; color: var(--muted); }
#back { display: none; }

.msgs { flex: 1; overflow-y: auto; padding: 16px max(16px, calc((100% - 780px) / 2)); display: flex; flex-direction: column; gap: 3px; }
.day {
  align-self: center; background: color-mix(in srgb, var(--panel) 85%, transparent); color: var(--muted); font-size: 12px;
  font-weight: 600; padding: 4px 12px; border-radius: 999px; margin: 12px 0 8px; box-shadow: var(--shadow);
}
.msg {
  max-width: min(78%, 540px); padding: 7px 12px 6px; border-radius: 18px 18px 18px 6px; background: var(--bubble-in);
  align-self: flex-start; box-shadow: var(--shadow); overflow-wrap: anywhere; white-space: pre-wrap; animation: in .18s ease-out;
}
.msg.out { align-self: flex-end; background: var(--bubble-out); color: #fff; border-radius: 18px 18px 6px 18px; }
.msg.out a { color: #fff; }
.msg.out .stamp { color: rgba(255, 255, 255, .78); }
.msg.cont { margin-top: -1px; }
.msg .from { font-size: 13px; font-weight: 700; color: var(--c); margin-bottom: 2px; }
.stamp { float: right; font-size: 11px; color: var(--muted); margin: 7px 0 -4px 12px; user-select: none; }
.msg.media { padding: 4px; }
.msg.media .text { padding: 4px 8px 3px; }
.msg.media .from { padding: 3px 8px 0; }
.msg img, .msg video { display: block; max-width: 100%; max-height: 440px; border-radius: 14px; background: #0001; }
.msg img { cursor: zoom-in; }
.msg audio { display: block; width: 280px; max-width: 100%; margin: 4px; }
.file { display: flex; gap: 12px; align-items: center; padding: 6px 8px 2px; text-decoration: none; color: inherit; min-width: 0; }
.file .ic { width: 46px; height: 46px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; flex: none; }
.msg.out .file .ic { background: #fff; color: var(--accent); }
.file .fmeta { display: grid; min-width: 0; }
.file b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.file small { opacity: .75; }
.progress { height: 4px; background: rgba(255, 255, 255, .3); border-radius: 4px; overflow: hidden; margin: 8px 8px 4px; }
.progress i { display: block; height: 100%; width: 0; background: #fff; transition: width .2s; }
@keyframes in { from { opacity: 0; transform: translateY(6px); } }

#composer { display: flex; padding: 10px max(12px, calc((100% - 780px) / 2)); padding-bottom: max(10px, env(safe-area-inset-bottom)); gap: 8px; }
.compose-box { flex: 1; display: flex; align-items: flex-end; gap: 6px; }
.compose-box .icon { background: var(--panel); box-shadow: var(--shadow); width: 48px; height: 48px; }
#text {
  flex: 1; min-width: 0; border: 0; background: var(--panel); border-radius: 24px; resize: none; outline: none;
  padding: 13px 18px; max-height: 180px; line-height: 1.4; box-shadow: var(--shadow);
}
.send {
  width: 48px; height: 48px; border-radius: 50%; color: #fff; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 60%, var(--accent-2)));
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 40%, transparent); transition: transform .1s;
}
.send:active { transform: scale(.94); }
.send svg { margin-left: -2px; }
.bar { flex: 1; padding: 14px; border-radius: 16px; background: var(--panel); text-align: center; color: var(--muted); box-shadow: var(--shadow); }
.bar.accent { color: var(--accent); font-weight: 700; }
.drop-hint {
  position: absolute; inset: 12px; border: 2px dashed var(--accent); border-radius: 20px; display: none; place-items: center;
  background: color-mix(in srgb, var(--panel) 85%, transparent); color: var(--accent); font-weight: 700; font-size: 18px; pointer-events: none;
}
#chat.drop .drop-hint { display: grid; }

/* ---------- Fenêtres ---------- */
dialog {
  border: 0; border-radius: 22px; padding: 0; background: var(--panel); color: var(--text); margin: auto;
  width: min(460px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); box-shadow: 0 30px 90px rgba(0, 0, 0, .35);
}
dialog[open] { animation: pop .16s ease-out; }
dialog::backdrop { background: rgba(8, 10, 22, .55); backdrop-filter: blur(4px); }
dialog form, .dlg-body { display: grid; gap: 14px; padding: 24px; }
dialog h2 { font-size: 20px; letter-spacing: -.01em; }
.actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.rules ul { padding-left: 20px; display: grid; gap: 6px; }
.info-top { display: grid; justify-items: center; gap: 6px; text-align: center; padding-bottom: 4px; }
.about { white-space: pre-wrap; background: var(--panel-2); border-radius: 14px; padding: 12px 14px; }
.inline { display: flex; gap: 8px; }
.inline .field { flex: 1; min-width: 0; }
.dlg-body .list { padding: 0; max-height: 320px; margin: 0 -10px; }
.dlg-body .item { cursor: default; }
.report { border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; display: grid; gap: 6px; }
.report blockquote { background: var(--panel-2); padding: 8px 12px; border-radius: 10px; white-space: pre-wrap; overflow-wrap: anywhere; }
.report .actions { justify-content: flex-start; }
.report .ghost { padding: 6px 10px; font-size: 14px; }
#viewer { background: transparent; box-shadow: none; width: auto; max-width: 96vw; max-height: 96dvh; cursor: zoom-out; }
#viewer img { display: block; max-width: 96vw; max-height: 92dvh; border-radius: 12px; }

#toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translate(-50%, 20px); z-index: 100;
  background: #1b1f2e; color: #fff; padding: 12px 18px; border-radius: 14px; box-shadow: 0 12px 32px rgba(0, 0, 0, .3);
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px);
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  #app { grid-template-columns: 1fr; }
  #side { border-right: 0; }
  #chat { position: fixed; inset: 0; z-index: 5; transform: translateX(100%); transition: transform .25s ease; }
  #app.open #chat { transform: none; }
  #back { display: grid; }
  .msg { max-width: 86%; }
  .msgs { padding: 12px 10px; }
  #composer { padding-left: 8px; padding-right: 8px; }
  .compose-box .icon, .send { width: 46px; height: 46px; }
}
