:root {
  color-scheme: dark;
  --rail: #141518;
  --side: #1c1d21;
  --bg: #24252a;
  --raised: #2d2e34;
  --hover: #303138;
  --active: #393a42;
  --line: #34353c;
  --text: #eceae6;
  --muted: #a1a1ab;
  --faint: #72737d;
  --accent: #f2b35e;
  --accent-ink: #241707;
  --online: #4fbf72;
  --idle: #e3a83a;
  --dnd: #ef5a5a;
  --offline: #80818b;
  --danger: #ef6f6c;
  --mention: rgba(242, 179, 94, 0.1);
  --glow: rgba(242, 179, 94, 0.5);
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.4);

  --font-body: 'Atkinson Hyperlegible', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-display: 'Bricolage Grotesque', 'Atkinson Hyperlegible', system-ui, sans-serif;
  --mono: ui-monospace, 'SF Mono', Consolas, monospace;
  --step--1: 0.8125rem;
  --step-0: 0.9375rem;
  --step-1: 1.0625rem;
  --r-sm: 6px;
  --r-md: 10px;
}

@media (prefers-color-scheme: light) {
  :root {
    color-scheme: light;
    --rail: #dcdce3;
    --side: #ebebf0;
    --bg: #f7f7fa;
    --raised: #ffffff;
    --hover: #e3e3ea;
    --active: #d6d6df;
    --line: #d6d6de;
    --text: #1f2026;
    --muted: #5b5c66;
    --faint: #8a8b95;
    --accent: #a8650f;
    --accent-ink: #ffffff;
    --online: #23944a;
    --idle: #c98a12;
    --dnd: #d63c3c;
    --offline: #8a8b95;
    --danger: #c43c3a;
    --mention: rgba(168, 101, 15, 0.09);
    --glow: rgba(206, 132, 30, 0.55);
    --shadow: 0 8px 28px rgba(30, 30, 50, 0.18);
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: var(--step-0)/1.45 var(--font-body);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
::selection { background: var(--accent); color: var(--accent-ink); }
svg.i { width: 20px; height: 20px; display: block; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.wordmark {
  font-family: var(--font-display); font-weight: 800; font-size: 2.75rem;
  letter-spacing: -0.04em; line-height: 1; margin: 0; color: var(--accent);
}

/* ---------- Boutons ---------- */
.btn-primary {
  background: var(--accent); color: var(--accent-ink); border: 0; border-radius: var(--r-sm);
  padding: 0.55rem 1rem; font-weight: 700;
}
.btn-primary:hover { filter: brightness(1.08); }
.btn-ghost {
  background: transparent; border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.5rem 0.9rem;
}
.btn-ghost:hover { background: var(--hover); }
.danger { color: var(--danger) !important; }
.btn-danger { background: var(--danger); color: #fff; border: 0; border-radius: var(--r-sm); padding: 0.55rem 1rem; font-weight: 700; }
.icon-btn {
  background: transparent; border: 0; border-radius: var(--r-sm);
  width: 2rem; height: 2rem; display: inline-grid; place-items: center;
  color: var(--muted); flex: none; padding: 0; font-size: 0.8rem; font-weight: 700;
}
.icon-btn:hover { background: var(--hover); color: var(--text); }
.icon-btn[aria-pressed="true"] { color: var(--danger); }
.icon-btn.active { color: var(--text); }
.link-btn { background: none; border: 0; padding: 0; color: inherit; text-align: left; }
.link-btn:hover { text-decoration: underline; }

/* ---------- Connexion ---------- */
.auth { height: 100%; display: grid; place-items: center; padding: 1.5rem; overflow-y: auto; }
.auth-card { width: min(380px, 100%); }
.auth-sub { color: var(--muted); margin: 0.75rem 0 2rem; }
.auth-tabs { display: flex; gap: 1.25rem; border-bottom: 1px solid var(--line); margin-bottom: 1.25rem; }
.auth-tabs button { background: none; border: 0; padding: 0.5rem 0; color: var(--muted); border-bottom: 2px solid transparent; margin-bottom: -1px; }
.auth-tabs button[aria-selected="true"] { color: var(--text); border-color: var(--accent); }
label { display: grid; gap: 0.3rem; margin-bottom: 0.9rem; font-size: var(--step--1); color: var(--muted); }
input:not([type="checkbox"]):not([type="radio"]):not([type="range"]), select {
  background: var(--rail); border: 1px solid var(--line); border-radius: var(--r-sm);
  padding: 0.55rem 0.7rem; font-size: var(--step-0); color: var(--text); width: 100%;
}
input:focus, select:focus { border-color: var(--accent); outline: none; }
.form-error { color: var(--danger); min-height: 1.3em; margin: 0 0 0.5rem; font-size: var(--step--1); }
.form-error.ok { color: var(--online); }
#auth-submit { width: 100%; padding: 0.75rem; }

/* ---------- Disposition ---------- */
.app {
  display: grid;
  grid-template-columns: 72px 240px minmax(0, 1fr);
  height: 100%;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: var(--rail);
}

/* Barre des serveurs */
.rail {
  background: var(--rail);
  display: flex; flex-direction: column; align-items: center; gap: 0.5rem;
  padding: 0.75rem 0; overflow-y: auto; scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail-sep { width: 32px; height: 2px; border-radius: 1px; background: var(--line); flex: none; }
.rail-item { position: relative; display: grid; place-items: center; width: 72px; flex: none; }
.rail-item::before {
  content: ""; position: absolute; left: 0; top: 50%; width: 4px; height: 0;
  margin-top: 0; border-radius: 0 4px 4px 0; background: var(--text);
  transition: height 0.15s ease, margin-top 0.15s ease;
}
.rail-item.unread::before { height: 8px; margin-top: -4px; }
.rail-item:hover::before { height: 20px; margin-top: -10px; }
.rail-item.current::before { height: 40px; margin-top: -20px; }
.rail-btn {
  width: 48px; height: 48px; border-radius: 50%; border: 0; padding: 0;
  background: var(--side); color: var(--text);
  display: grid; place-items: center; overflow: hidden;
  font-family: var(--font-display); font-weight: 700; font-size: 1rem;
  transition: border-radius 0.15s ease, background 0.15s ease;
}
.rail-btn img { width: 100%; height: 100%; object-fit: cover; }
.rail-item:hover .rail-btn, .rail-item.current .rail-btn { border-radius: 16px; }
.rail-item.current .rail-btn, .rail-btn.home:hover { background: var(--accent); color: var(--accent-ink); }
.rail-btn.add { color: var(--online); font-size: 1.5rem; font-weight: 400; }
.rail-btn.add:hover { background: var(--online); color: #fff; border-radius: 16px; }
.rail-badge {
  position: absolute; right: 10px; bottom: -2px; min-width: 18px; height: 18px; padding: 0 5px;
  border-radius: 9px; background: var(--danger); color: #fff; font-size: 0.7rem; font-weight: 700;
  display: grid; place-items: center; border: 3px solid var(--rail); box-sizing: content-box;
}

/* Colonne des salons */
.sidebar { background: var(--side); display: flex; flex-direction: column; min-height: 0; border-radius: 12px 0 0 0; }
.side-head {
  display: flex; align-items: center; gap: 0.5rem;
  height: 3rem; padding: 0 0.75rem 0 1rem; border-bottom: 1px solid var(--line); flex: none;
}
.side-head-btn {
  flex: 1; display: flex; align-items: center; justify-content: space-between; gap: 0.5rem;
  background: none; border: 0; padding: 0.35rem 0.25rem; border-radius: var(--r-sm);
  font-family: var(--font-display); font-weight: 700; font-size: var(--step-1); text-align: left; min-width: 0;
}
.side-head-btn span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-head-btn:hover { background: var(--hover); }
.side-head h3 { margin: 0; font-family: var(--font-display); font-size: var(--step-1); flex: 1; }
.side-body { flex: 1; overflow-y: auto; padding: 0.5rem 0.5rem 1rem; }

.chan-group { margin-top: 1rem; }
.chan-group:first-child { margin-top: 0.25rem; }
.chan-group-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 0.25rem 0.2rem 0.4rem; font-size: 0.75rem; color: var(--muted); font-weight: 700;
}
.chan-group-head .icon-btn { width: 1.5rem; height: 1.5rem; }
.chan { display: flex; align-items: center; border-radius: var(--r-sm); color: var(--faint); position: relative; margin-bottom: 1px; }
.chan:hover { background: var(--hover); color: var(--text); }
.chan.current { background: var(--active); color: var(--text); }
.chan.unread { color: var(--text); font-weight: 700; }
.chan.unread::before {
  content: ""; position: absolute; left: -0.5rem; top: 50%; width: 4px; height: 8px; margin-top: -4px;
  border-radius: 0 4px 4px 0; background: var(--text);
}
.chan-main {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.45rem;
  padding: 0.35rem 0.5rem; background: none; border: 0; color: inherit; font-weight: inherit; text-align: left;
}
.chan-main svg.i { width: 18px; height: 18px; flex: none; opacity: 0.8; }
.chan-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chan-actions { display: none; gap: 0.1rem; padding-right: 0.25rem; }
.chan:hover .chan-actions, .chan:focus-within .chan-actions { display: flex; }
.chan-actions button { background: none; border: 0; color: var(--muted); padding: 0.1rem 0.25rem; border-radius: 4px; display: grid; place-items: center; }
.chan-actions button:hover { color: var(--text); background: var(--active); }
.chan-actions svg.i { width: 15px; height: 15px; }

.voice-people { list-style: none; margin: 0 0 0.25rem; padding: 0 0 0 1.75rem; }
.voice-people li {
  display: flex; align-items: center; gap: 0.45rem; padding: 0.2rem 0.4rem; border-radius: var(--r-sm);
  font-size: var(--step--1); color: var(--muted); cursor: default;
}
.voice-people li:hover { background: var(--hover); color: var(--text); }
.voice-people .speaking .face { box-shadow: 0 0 0 2px var(--online); }
.badges { margin-left: auto; display: flex; gap: 0.25rem; align-items: center; color: var(--faint); }
.badges svg.i { width: 14px; height: 14px; }
.badge-live { background: var(--danger); color: #fff; font-size: 0.6rem; font-weight: 700; padding: 0 0.3rem; border-radius: 3px; }

/* Messages privés dans la colonne */
.dm-row { display: flex; align-items: center; gap: 0.65rem; width: 100%; padding: 0.35rem 0.5rem; border: 0; background: none; border-radius: var(--r-sm); color: var(--muted); text-align: left; }
.dm-row:hover { background: var(--hover); color: var(--text); }
.dm-row.current { background: var(--active); color: var(--text); }
.dm-row.unread { color: var(--text); font-weight: 700; }
.dm-row-text { display: grid; min-width: 0; line-height: 1.25; }
.dm-row-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-row-text small { color: var(--faint); font-weight: 400; font-size: 0.75rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-row .in-call { margin-left: auto; color: var(--online); }

/* Dock vocal */
.voice-dock { border-top: 1px solid var(--line); padding: 0.6rem 0.6rem 0.5rem; display: grid; gap: 0.5rem; background: var(--side); }
.voice-dock-top { display: flex; align-items: center; gap: 0.5rem; }
.voice-dock-info { display: grid; line-height: 1.25; flex: 1; min-width: 0; }
.voice-dock-status { color: var(--online); font-weight: 700; font-size: var(--step--1); }
.voice-dock-status.wait { color: var(--idle); }
.voice-dock-info .link-btn { font-size: 0.75rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.voice-controls { display: flex; gap: 0.3rem; }
.ctrl {
  flex: 1; background: var(--raised); border: 0; border-radius: var(--r-sm);
  padding: 0.35rem 0.3rem; font-size: 0.75rem; font-weight: 700; color: var(--text);
}
.ctrl:hover { background: var(--active); }
.ctrl[aria-pressed="true"] { background: var(--accent); color: var(--accent-ink); }

/* Panneau utilisateur */
.me { display: flex; align-items: center; gap: 0.1rem; padding: 0.45rem 0.4rem; background: var(--rail); flex: none; }
.me-id {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 0.55rem;
  background: none; border: 0; padding: 0.2rem 0.3rem; border-radius: var(--r-sm); text-align: left;
}
.me-id:hover { background: var(--hover); }
.me-text { display: grid; line-height: 1.2; min-width: 0; }
.me-text strong { font-size: var(--step--1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.me-text small { font-size: 0.72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Avatars et statuts ---------- */
.av { --s: 40px; display: inline-block; vertical-align: middle; position: relative; width: var(--s); height: var(--s); flex: none; }
.av .face {
  width: 100%; height: 100%; border-radius: 50%; overflow: hidden;
  background: var(--c, var(--accent)); color: #1c1d21;
  display: grid; place-items: center;
  font-family: var(--font-display); font-weight: 800; font-size: calc(var(--s) * 0.42); text-transform: uppercase;
}
.av .face img { width: 100%; height: 100%; object-fit: cover; display: block; }
.av .dot {
  --d: max(10px, calc(var(--s) * 0.32));
  position: absolute; right: -2px; bottom: -2px; width: var(--d); height: var(--d);
  border-radius: 50%; border: 3px solid var(--ring, var(--side)); box-sizing: content-box;
  background: var(--offline);
}
.dot.online { background: var(--online); }
.dot.idle { background: radial-gradient(circle at 22% 22%, var(--ring, var(--side)) 38%, var(--idle) 40%); }
.dot.dnd { background: var(--dnd); }
.dot.dnd::after { content: ""; position: absolute; left: 22%; right: 22%; top: 50%; height: 2px; margin-top: -1px; border-radius: 1px; background: var(--ring, var(--side)); }
.dot.offline { background: radial-gradient(circle, var(--ring, var(--side)) 32%, var(--offline) 34%); }
.dot.inline { position: static; display: inline-block; border: 0; --d: 10px; flex: none; }

/* ---------- Zone principale ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; background: var(--bg); }
.main-head {
  display: flex; align-items: center; gap: 0.5rem; height: 3rem; padding: 0 0.75rem 0 1rem;
  border-bottom: 1px solid var(--line); flex: none; min-width: 0;
}
.channel-title {
  font-family: var(--font-display); font-weight: 700; font-size: var(--step-1);
  margin: 0; display: flex; align-items: center; gap: 0.4rem; white-space: nowrap; min-width: 0;
}
.channel-title svg.i { color: var(--faint); }
.channel-title .av { --s: 24px; --ring: var(--bg); }
.channel-sub { color: var(--muted); font-size: var(--step--1); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.head-actions { display: flex; align-items: center; gap: 0.25rem; margin-left: auto; }
.search input { width: 150px; padding: 0.3rem 0.6rem !important; font-size: var(--step--1) !important; transition: width 0.15s ease; }
.search input:focus { width: 220px; }
.only-mobile { display: none !important; }

.main-body { flex: 1; display: flex; min-height: 0; }
.center { flex: 1; display: flex; flex-direction: column; min-width: 0; position: relative; }
.panel { width: 240px; flex: none; background: var(--side); overflow-y: auto; border-left: 1px solid var(--line); }
.panel:empty { display: none; }

/* Accueil */
.home-view { flex: 1; overflow-y: auto; padding: 2rem 1.5rem; }
.home-view h3 { font-family: var(--font-display); font-size: 1.5rem; letter-spacing: -0.02em; margin: 0 0 0.25rem; }
.home-view > p { color: var(--muted); margin: 0 0 1.5rem; }
.people { display: grid; gap: 0.25rem; max-width: 640px; }
.person { display: flex; align-items: center; gap: 0.8rem; padding: 0.6rem 0.75rem; border-radius: var(--r-md); border-top: 1px solid var(--line); }
.person:hover { background: var(--hover); }
.person .av { --ring: var(--bg); }
.person:hover .av { --ring: var(--hover); }
.person-text { flex: 1; display: grid; line-height: 1.3; min-width: 0; }
.person-text small { color: var(--muted); }

/* ---------- Messages ---------- */
.text-view { flex: 1; display: flex; flex-direction: column; min-height: 0; position: relative; }
.messages { flex: 1; overflow-y: auto; padding: 1rem 0 0.5rem; overscroll-behavior: contain; }
.load-more { display: block; margin: 0 auto 1rem; }
.channel-start { padding: 1rem 1rem 0.5rem; }
.channel-start .start-icon { width: 68px; height: 68px; border-radius: 50%; background: var(--raised); display: grid; place-items: center; margin-bottom: 0.5rem; }
.channel-start .start-icon svg.i { width: 36px; height: 36px; }
.channel-start .av { --s: 80px; margin-bottom: 0.5rem; }
.channel-start h3 { font-family: var(--font-display); font-size: 1.85rem; margin: 0 0 0.25rem; letter-spacing: -0.02em; }
.channel-start p { margin: 0; color: var(--muted); }
.day-sep { display: flex; align-items: center; gap: 0.6rem; margin: 1rem 1rem 0.25rem; color: var(--faint); font-size: 0.75rem; font-weight: 700; }
.day-sep::before, .day-sep::after { content: ""; height: 1px; background: var(--line); flex: 1; }

.msg { display: grid; grid-template-columns: 40px minmax(0, 1fr); column-gap: 1rem; padding: 0.12rem 1rem 0.12rem; position: relative; }
.msg.head { margin-top: 1rem; }
.msg:hover { background: var(--hover); }
.msg .av, .msg .gutter-time { grid-column: 1; grid-row: 1 / span 2; }
.msg .av { margin-top: 0.15rem; cursor: pointer; }
.msg-content { grid-row: 1 / span 2; }
.msg.has-reply .reply-quote { grid-column: 2; grid-row: 1; }
.msg.has-reply .av { grid-row: 2 / span 2; }
.msg.has-reply .msg-content { grid-row: 2 / span 2; }
.msg.follow .gutter-time { font-size: 0.65rem; color: var(--faint); opacity: 0; align-self: start; padding-top: 0.25rem; text-align: right; }
.msg.follow:hover .gutter-time { opacity: 1; }
.msg-content { grid-column: 2; min-width: 0; }
.msg-meta { display: flex; align-items: baseline; gap: 0.5rem; }
.msg-author { font-weight: 700; color: var(--c, var(--text)); background: none; border: 0; padding: 0; }
.msg-author:hover { text-decoration: underline; }
.msg-time { font-size: 0.72rem; color: var(--faint); }
.msg-body { overflow-wrap: anywhere; white-space: pre-wrap; }
.msg-body .edited { font-size: 0.68rem; color: var(--faint); margin-left: 0.25rem; }
.msg-body code { background: var(--rail); padding: 0.1rem 0.3rem; border-radius: 4px; font-family: var(--mono); font-size: 0.85em; }
.msg-body pre { background: var(--rail); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.6rem 0.75rem; margin: 0.35rem 0; overflow-x: auto; white-space: pre; }
.msg-body pre code { background: none; padding: 0; }
.msg-body a { color: var(--accent); }
.msg-body blockquote { margin: 0.1rem 0; padding-left: 0.7rem; border-left: 4px solid var(--line); }
.msg-body .spoiler { background: var(--faint); color: transparent; border-radius: 3px; cursor: pointer; }
.msg-body .spoiler.shown { background: var(--raised); color: inherit; }
.msg-body .big-emoji { font-size: 2.6rem; line-height: 1.2; }
.mention { background: var(--mention); color: var(--accent); border-radius: 3px; padding: 0 0.15rem; font-weight: 700; }
.msg.mentions-me { background: var(--mention); box-shadow: inset 3px 0 0 var(--accent); }
.msg.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: var(--mention); } 100% { background: transparent; } }
.pin-mark { font-size: 0.7rem; color: var(--faint); display: inline-flex; align-items: center; gap: 0.2rem; }
.pin-mark svg.i { width: 12px; height: 12px; }

.reply-quote {
  display: flex; align-items: center; gap: 0.4rem; font-size: var(--step--1); color: var(--muted);
  padding-left: 1.2rem; position: relative; margin: 0.1rem 0 0.15rem; min-width: 0; cursor: pointer;
  background: none; border: 0; text-align: left; width: 100%;
}
.reply-quote::before {
  content: ""; position: absolute; left: -1.85rem; top: 50%; width: 2.6rem; height: 0.65rem;
  border-left: 2px solid var(--faint); border-top: 2px solid var(--faint); border-top-left-radius: 6px; opacity: 0.6;
}
.reply-quote .av { --s: 16px; grid-row: auto; margin: 0; }
.reply-quote strong { color: var(--c, var(--text)); flex: none; }
.reply-quote span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.reply-quote:hover span { color: var(--text); }

.attach { margin-top: 0.35rem; }
.attach img, .attach video { display: block; max-width: min(420px, 100%); max-height: 320px; border-radius: var(--r-sm); cursor: zoom-in; }
.attach audio { width: min(360px, 100%); }
.gif img { display: block; max-width: min(300px, 100%); border-radius: var(--r-sm); margin-top: 0.2rem; }
.file-card {
  display: inline-flex; align-items: center; gap: 0.6rem; padding: 0.6rem 0.8rem; border: 1px solid var(--line);
  border-radius: var(--r-md); background: var(--side); color: var(--text); text-decoration: none; max-width: 100%;
}
.file-card:hover { border-color: var(--accent); }
.file-card small { color: var(--muted); }

.reactions { display: flex; flex-wrap: wrap; gap: 0.25rem; margin-top: 0.3rem; }
.reaction {
  display: inline-flex; align-items: center; gap: 0.35rem; padding: 0.1rem 0.45rem; border-radius: 8px;
  border: 1px solid transparent; background: var(--raised); font-size: var(--step--1);
}
.reaction:hover { border-color: var(--faint); }
.reaction.mine { border-color: var(--accent); background: var(--mention); }
.reaction.add { color: var(--muted); opacity: 0; }
.msg:hover .reaction.add { opacity: 1; }

.msg-tools {
  position: absolute; right: 1rem; top: -1rem; display: none; gap: 0;
  background: var(--raised); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.1rem; z-index: 2;
  box-shadow: var(--shadow);
}
.msg:hover .msg-tools, .msg:focus-within .msg-tools { display: flex; }
.msg-tools button { background: none; border: 0; border-radius: 4px; width: 2rem; height: 1.9rem; display: grid; place-items: center; color: var(--muted); }
.msg-tools button:hover { background: var(--hover); color: var(--text); }
.msg-tools svg.i { width: 18px; height: 18px; }

.edit-box textarea { width: 100%; resize: none; background: var(--raised); border: 1px solid var(--accent); border-radius: var(--r-sm); padding: 0.5rem 0.6rem; color: var(--text); }
.edit-box small { color: var(--muted); font-size: 0.72rem; }

.typing { height: 1.4rem; padding: 0 1rem; font-size: 0.75rem; color: var(--muted); }

/* Zone de saisie */
.composer { padding: 0 1rem 1.25rem; }
.composer-row {
  display: flex; align-items: flex-end; gap: 0.25rem; background: var(--raised); border-radius: var(--r-md); padding: 0.3rem 0.4rem;
}
#input { flex: 1; resize: none; border: 0; background: transparent; outline: none; padding: 0.4rem 0.25rem; max-height: 40vh; line-height: 1.45; min-width: 0; }
#btn-gif { font-size: 0.7rem; border: 2px solid currentColor; width: auto; height: 1.4rem; padding: 0 0.3rem; margin: 0.3rem 0.2rem; border-radius: 4px; }
.reply-bar, .upload-preview {
  display: flex; align-items: center; gap: 0.6rem; background: var(--side); border-radius: var(--r-md) var(--r-md) 0 0;
  padding: 0.45rem 0.75rem; font-size: var(--step--1); color: var(--muted);
}
.reply-bar strong { color: var(--text); }
.reply-bar .grow, .upload-preview .grow { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-preview img { width: 3rem; height: 3rem; object-fit: cover; border-radius: 4px; }
.reply-bar + .upload-preview { border-radius: 0; border-top: 1px solid var(--line); }
.reply-bar:not([hidden]) ~ .composer-row, .upload-preview:not([hidden]) ~ .composer-row { border-top-left-radius: 0; border-top-right-radius: 0; }

.dropzone {
  position: absolute; inset: 0.75rem; z-index: 10; display: grid; place-items: center;
  border: 2px dashed var(--accent); border-radius: var(--r-md);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  font-family: var(--font-display); font-size: 1.5rem; font-weight: 700; color: var(--accent); pointer-events: none;
}

/* ---------- Panneau de droite ---------- */
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 0.75rem 0.75rem 0.5rem 1rem; position: sticky; top: 0; background: var(--side); z-index: 1; }
.panel-head h4 { margin: 0; font-family: var(--font-display); font-size: var(--step-0); }
.panel-group { margin: 1rem 0.5rem 0.3rem 1rem; font-size: 0.75rem; font-weight: 700; color: var(--muted); }
.member { display: flex; align-items: center; gap: 0.65rem; padding: 0.3rem 0.5rem; margin: 0 0.5rem; border-radius: var(--r-sm); width: calc(100% - 1rem); background: none; border: 0; text-align: left; }
.member:hover { background: var(--hover); }
.member:hover .av { --ring: var(--hover); }
.member.offline { opacity: 0.4; }
.member .av { --s: 32px; }
.member-text { display: grid; line-height: 1.2; min-width: 0; }
.member-name { font-weight: 700; color: var(--c); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.member-text small { color: var(--muted); font-size: 0.72rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.panel-list { padding: 0 0.5rem 1rem; display: grid; gap: 0.5rem; }
.mini {
  background: var(--bg); border-radius: var(--r-md); padding: 0.55rem 0.65rem; border: 1px solid var(--line);
  display: grid; gap: 0.2rem; text-align: left; color: var(--text); width: 100%;
}
.mini:hover { border-color: var(--faint); }
.mini-head { display: flex; gap: 0.4rem; align-items: center; font-size: 0.75rem; color: var(--faint); }
.mini-head strong { color: var(--c, var(--text)); font-size: var(--step--1); }
.mini-body { font-size: var(--step--1); overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.mini mark { background: var(--mention); color: var(--accent); border-radius: 2px; }
.panel-empty { color: var(--muted); font-size: var(--step--1); padding: 1rem; text-align: center; }

/* ---------- Popovers ---------- */
.popover-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
.pop {
  position: fixed; pointer-events: auto; background: var(--raised); border: 1px solid var(--line);
  border-radius: var(--r-md); box-shadow: var(--shadow); max-width: calc(100vw - 16px);
}
.menu { padding: 0.35rem; min-width: 200px; display: grid; }
.menu button { display: flex; align-items: center; gap: 0.6rem; background: none; border: 0; padding: 0.45rem 0.6rem; border-radius: 4px; text-align: left; font-size: var(--step--1); }
.menu button:hover { background: var(--accent); color: var(--accent-ink); }
.menu button.danger:hover { background: var(--danger); color: #fff !important; }
.menu hr { border: 0; height: 1px; background: var(--line); margin: 0.3rem 0.25rem; }
.menu .status-item { display: grid; grid-template-columns: auto 1fr; column-gap: 0.6rem; }
.menu .status-item small { grid-column: 2; color: inherit; opacity: 0.75; font-size: 0.72rem; }
.menu input { margin: 0.25rem 0 0.1rem; }

.emoji-picker { width: 352px; height: 380px; display: flex; flex-direction: column; }
.emoji-tabs { display: flex; gap: 0.1rem; padding: 0.4rem; border-bottom: 1px solid var(--line); }
.emoji-tabs button { background: none; border: 0; border-radius: 4px; font-size: 1.1rem; padding: 0.15rem 0.3rem; opacity: 0.6; }
.emoji-tabs button:hover, .emoji-tabs button.on { opacity: 1; background: var(--hover); }
.emoji-scroll { flex: 1; overflow-y: auto; padding: 0.25rem 0.5rem 0.5rem; }
.emoji-scroll h5 { margin: 0.5rem 0.2rem 0.2rem; font-size: 0.72rem; color: var(--muted); }
.emoji-grid { display: grid; grid-template-columns: repeat(9, 1fr); }
.emoji-grid button { background: none; border: 0; font-size: 1.45rem; line-height: 1; padding: 0.3rem 0; border-radius: 6px; }
.emoji-grid button:hover { background: var(--hover); }

.gif-picker { width: 420px; height: 420px; display: flex; flex-direction: column; }
.gif-picker form { padding: 0.5rem; border-bottom: 1px solid var(--line); }
.gif-grid { flex: 1; overflow-y: auto; padding: 0.5rem; display: grid; grid-template-columns: 1fr 1fr; gap: 0.4rem; align-content: start; }
.gif-grid button { border: 0; padding: 0; background: var(--rail); border-radius: var(--r-sm); overflow: hidden; height: 110px; }
.gif-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gif-picker .panel-empty { grid-column: 1 / -1; }
.gif-credit { font-size: 0.65rem; color: var(--faint); text-align: right; padding: 0 0.6rem 0.35rem; }

.profile-card { width: 300px; overflow: hidden; }
.profile-banner { height: 64px; background: var(--c); }
.profile-card .av { --s: 84px; --ring: var(--raised); margin: -44px 0 0 1rem; }
.profile-card .av .face { box-shadow: 0 0 0 6px var(--raised); }
.profile-body { padding: 0.5rem 1rem 1rem; display: grid; gap: 0.35rem; }
.profile-body h4 { margin: 0; font-family: var(--font-display); font-size: 1.25rem; }
.profile-body .status-line { color: var(--muted); font-size: var(--step--1); display: flex; align-items: center; gap: 0.4rem; }
.profile-body .custom { background: var(--bg); border-radius: var(--r-sm); padding: 0.5rem 0.65rem; font-size: var(--step--1); }
.profile-body .btn-primary { margin-top: 0.4rem; }

.volume-pop { padding: 0.8rem 0.9rem; width: 240px; display: grid; gap: 0.5rem; }
.volume-pop h5 { margin: 0; font-size: var(--step--1); }
.volume-pop input[type="range"] { width: 100%; accent-color: var(--accent); }
.volume-pop .row { display: flex; justify-content: space-between; font-size: 0.75rem; color: var(--muted); }

.soundboard { width: 300px; padding: 0.6rem; display: grid; gap: 0.5rem; }
.soundboard h5 { margin: 0 0.2rem; font-size: var(--step--1); display: flex; justify-content: space-between; align-items: center; }
.sound-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.35rem; max-height: 260px; overflow-y: auto; }
.sound { position: relative; background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-sm); padding: 0.45rem 0.3rem; display: grid; gap: 0.1rem; text-align: center; font-size: 0.72rem; }
.sound:hover { border-color: var(--accent); }
.sound .e { font-size: 1.3rem; }
.sound .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sound .del { position: absolute; top: 2px; right: 2px; width: 1.1rem; height: 1.1rem; border-radius: 50%; border: 0; background: var(--danger); color: #fff; font-size: 0.6rem; display: none; place-items: center; padding: 0; }
.sound:hover .del { display: grid; }

/* ---------- Vocal ---------- */
.stage-view { flex: 1; display: flex; flex-direction: column; justify-content: center; min-height: 0; overflow-y: auto; padding: 1.25rem; gap: 1rem; background: var(--rail); }
.stage { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(240px, 100%), 1fr)); gap: 0.75rem; align-content: center; flex: 1; }
.stage:empty { display: none; }
.stage.has-screen { grid-template-columns: 1fr; }
.stage.has-screen .tile:not(.screen) { display: none; }
.stage.has-screen .seat-row { display: flex; }
.tile { position: relative; aspect-ratio: 16 / 10; background: var(--side); border-radius: var(--r-md); display: grid; place-items: center; overflow: hidden; transition: box-shadow 0.15s ease; }
.tile .av { --s: 84px; }
.tile .av .face { transition: box-shadow 0.15s ease; }
.tile.speaking { box-shadow: 0 0 0 2px var(--online); }
.tile.speaking .av .face { box-shadow: 0 0 0 3px var(--side), 0 0 0 6px var(--online); }
.tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
.tile.screen video { object-fit: contain; }
.tile.screen { aspect-ratio: 16 / 9; cursor: zoom-in; }
.tile.mirror video { transform: scaleX(-1); }
.tile-label { position: absolute; left: 0.5rem; bottom: 0.5rem; display: flex; gap: 0.35rem; align-items: center; padding: 0.2rem 0.5rem; border-radius: 6px; background: rgba(15, 15, 20, 0.7); color: #f1efea; font-size: var(--step--1); font-weight: 700; }
.tile-label svg.i { width: 14px; height: 14px; color: var(--danger); }
.tile-menu { position: absolute; top: 0.4rem; right: 0.4rem; background: rgba(15, 15, 20, 0.7); color: #fff; opacity: 0; }
.tile:hover .tile-menu, .tile-menu:focus-visible { opacity: 1; }
.seat-row { display: none; gap: 0.6rem; flex-wrap: wrap; justify-content: center; }
.seat-row .av { --s: 44px; --ring: var(--rail); }
.seat-row .speaking .face { box-shadow: 0 0 0 3px var(--rail), 0 0 0 5px var(--online); }
.stage-empty { text-align: center; color: var(--muted); margin: 0; }
.stage-join { display: grid; place-items: center; }
.stage-join .btn-primary { padding: 0.75rem 1.5rem; font-size: var(--step-1); }

.call-strip { background: var(--rail); padding: 0.9rem 1rem; display: grid; gap: 0.75rem; flex: none; max-height: 55%; overflow-y: auto; }
.call-strip .stage { grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 280px)); justify-content: center; }
.call-actions { display: flex; justify-content: center; gap: 0.5rem; }

/* Appel entrant */
.incoming {
  position: fixed; left: 50%; top: calc(1rem + env(safe-area-inset-top, 0px)); transform: translateX(-50%); z-index: 80;
  background: var(--raised); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow);
  padding: 1rem 1.25rem; display: flex; align-items: center; gap: 1rem; min-width: 300px;
}
.incoming .av { --s: 52px; --ring: var(--raised); }
.incoming .av .face { animation: ring 1.4s ease-out infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 var(--glow); } 100% { box-shadow: 0 0 0 14px transparent; } }
.incoming-text { flex: 1; display: grid; line-height: 1.3; }
.incoming-text small { color: var(--muted); }
.incoming .btn-ok { background: var(--online); color: #fff; border: 0; border-radius: 50%; width: 2.6rem; height: 2.6rem; display: grid; place-items: center; }
.incoming .btn-no { background: var(--danger); color: #fff; border: 0; border-radius: 50%; width: 2.6rem; height: 2.6rem; display: grid; place-items: center; }

/* ---------- Modales ---------- */
.modal { border: 1px solid var(--line); border-radius: var(--r-md); background: var(--raised); color: var(--text); padding: 0; width: min(440px, calc(100% - 2rem)); }
.modal::backdrop { background: rgba(8, 8, 12, 0.65); }
.modal-body { padding: 1.25rem; }
.modal h3 { font-family: var(--font-display); font-size: 1.35rem; margin: 0 0 1rem; letter-spacing: -0.02em; }
.modal h4 { margin: 1.4rem 0 0.6rem; font-size: var(--step--1); color: var(--muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 0.5rem; }
label.check { display: flex; align-items: center; gap: 0.55rem; color: var(--text); font-size: var(--step-0); }
label.check input { width: auto; accent-color: var(--accent); }
.hint { color: var(--muted); font-size: var(--step--1); }
.swatches { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.swatch { width: 2rem; height: 2rem; border-radius: 50%; border: 2px solid transparent; }
.swatch[aria-pressed="true"] { border-color: var(--text); box-shadow: inset 0 0 0 3px var(--raised); }
.stack { display: grid; max-width: 420px; }
.stack .btn-ghost { justify-self: start; }
input[type="range"] { accent-color: var(--accent); }

.modal-wide { width: min(860px, calc(100% - 2rem)); height: min(620px, calc(100% - 2rem)); }
.settings { display: grid; grid-template-columns: 200px 1fr; height: 100%; position: relative; }
.settings-nav { background: var(--side); padding: 1.25rem 0.6rem; display: flex; flex-direction: column; gap: 0.15rem; }
.settings-nav button { background: none; border: 0; text-align: left; padding: 0.45rem 0.65rem; border-radius: var(--r-sm); color: var(--muted); }
.settings-nav button:hover { background: var(--hover); color: var(--text); }
.settings-nav button[aria-selected="true"] { background: var(--active); color: var(--text); }
.settings-logout { margin-top: auto; color: var(--danger) !important; }
.settings-body { padding: 1.5rem 2rem; overflow-y: auto; }
.settings-close { position: absolute; top: 0.75rem; right: 0.75rem; }
.profile-edit { display: flex; align-items: center; gap: 1.25rem; }
.profile-edit .av { --s: 88px; }
.profile-edit-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.radio-row { border: 0; padding: 0; margin: 0 0 0.9rem; display: grid; gap: 0.35rem; }
.radio-row legend { font-size: var(--step--1); color: var(--muted); margin-bottom: 0.35rem; padding: 0; }
.ptt-row { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; margin-bottom: 0.9rem; font-size: var(--step--1); color: var(--muted); }
.ptt-row .btn-ghost { font-family: var(--mono); color: var(--text); min-width: 5rem; }
.ptt-row small { flex-basis: 100%; }

/* ---------- Divers ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(1.5rem + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 0.6rem 1rem; border-radius: var(--r-sm); z-index: 100;
  max-width: calc(100% - 2rem); font-weight: 700;
}
.viewer { position: fixed; inset: 0; z-index: 90; background: rgba(8, 6, 12, 0.92); display: grid; place-items: center; padding: 1.5rem; cursor: zoom-out; }
.viewer img, .viewer video { max-width: 100%; max-height: 100%; border-radius: var(--r-sm); }
.scrim { display: none; }

/* ---------- Écrans moyens ---------- */
@media (max-width: 1100px) {
  .panel { position: fixed; right: 0; top: 0; bottom: 0; z-index: 30; box-shadow: var(--shadow); padding-top: env(safe-area-inset-top, 0px); }
  .search input { width: 120px; }
  .search input:focus { width: 170px; }
}

/* ---------- Mobile ---------- */
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  .rail, .sidebar { position: fixed; top: 0; bottom: 0; z-index: 30; transition: transform 0.2s ease; }
  .rail { left: 0; width: 72px; transform: translateX(-312px); padding-top: calc(0.75rem + env(safe-area-inset-top, 0px)); }
  .sidebar { left: 72px; width: min(240px, calc(100vw - 72px)); transform: translateX(-312px); border-radius: 0; padding-top: env(safe-area-inset-top, 0px); padding-bottom: env(safe-area-inset-bottom, 0px); }
  .app.show-sidebar .rail, .app.show-sidebar .sidebar { transform: none; }
  .app.show-sidebar .scrim, .app.show-panel .scrim { display: block; position: fixed; inset: 0; z-index: 20; background: rgba(8, 8, 12, 0.55); }
  .only-mobile { display: inline-grid !important; }
  .search { display: none; }
  .channel-sub { display: none; }
  .msg { padding: 0.12rem 0.6rem; column-gap: 0.7rem; }
  .composer { padding: 0 0.5rem 0.5rem; }
  .stage-view { padding: 0.75rem; }
  .chan-actions { display: flex; }
  .settings { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .settings-nav { flex-direction: row; overflow-x: auto; padding: 0.6rem 2.75rem 0.6rem 0.6rem; }
  .settings-nav button { white-space: nowrap; }
  .settings-logout { margin-top: 0; }
  .settings-body { padding: 1rem; }
  .emoji-picker, .gif-picker { width: calc(100vw - 16px); }
}

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