:root {
  --accent: #1b5bd8; --accent-2: #3a76f0; --accent-soft: #e6eeff;
  --bg: #ffffff; --bg-2: #f4f5f7; --bg-3: #e9ebef; --fg: #15171a; --muted: #6b7280; --line: #e3e5e9;
  --in: #e9ebef; --in-fg: #15171a; --out: #1b5bd8; --out-fg: #fff; --danger: #d93025; --ok: #1e9e4a;
  --shadow: 0 10px 40px rgba(0,0,0,.18); --radius: 18px;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121316; --bg-2: #1b1c20; --bg-3: #2a2c31; --fg: #e9eaee; --muted: #9aa0aa; --line: #2b2d33;
    --in: #2a2c31; --in-fg: #e9eaee; --accent-soft: #1d2b4a; --shadow: 0 10px 40px rgba(0,0,0,.6);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--fg);
  font: 15px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, Inter, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, textarea, select { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.grow { flex: 1; }
#app { height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* icônes */
.ic { display: inline-flex; width: 22px; height: 22px; flex: none; }
.ic svg { width: 100%; height: 100%; }
.ic.tiny { width: 14px; height: 14px; vertical-align: -2px; }
.inline-icon .ic { width: 14px; height: 14px; vertical-align: -2px; }
.icon-btn { border: 0; background: transparent; width: 40px; height: 40px; border-radius: 50%; display: inline-grid; place-items: center;
  cursor: pointer; color: var(--fg); flex: none; }
.icon-btn:hover { background: var(--bg-3); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.on { color: var(--accent); }
.icon-btn.send { background: var(--accent); color: #fff; }
.icon-btn.send:hover { background: var(--accent-2); }

/* boutons */
.btn { border: 1px solid var(--line); background: var(--bg-2); padding: 10px 16px; border-radius: 999px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 500; }
.btn:hover { background: var(--bg-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-2); }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .6; cursor: default; }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; }
.link.danger { color: var(--danger); }

/* écrans d'accueil */
.screen { flex: 1; display: grid; place-items: center; padding: 20px; background: var(--bg-2); overflow: auto; }
.center-card { width: min(420px, 100%); background: var(--bg); border-radius: 24px; padding: 28px; box-shadow: var(--shadow);
  display: flex; flex-direction: column; gap: 14px; text-align: center; }
.center-card h2 { margin: 0; }
.center-card label { text-align: left; }
.logo { width: 72px; height: 72px; margin: 0 auto; border-radius: 20px; }
.logo.big { width: 96px; height: 96px; }
label { display: flex; flex-direction: column; gap: 6px; font-size: 14px; color: var(--muted); }
label.check { flex-direction: row; align-items: center; gap: 10px; color: var(--fg); cursor: pointer; }
input:not([type=checkbox]), textarea, select { width: 100%; padding: 11px 14px; border: 1px solid var(--line); border-radius: 12px;
  background: var(--bg); outline: none; }
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--accent); }
.hint { font-size: 12.5px; color: var(--muted); margin: 0; text-align: left; }
.form-error { color: var(--danger); min-height: 1em; margin: 0; font-size: 14px; }

/* disposition principale */
#screen-main { flex: 1; display: flex; min-height: 0; }
#sidebar { width: 360px; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--bg); min-height: 0; }
.side-head { display: flex; align-items: center; gap: 10px; padding: 12px 10px 8px 14px; }
.side-title { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.side-title h1 { font-size: 18px; margin: 0; }
.conn { font-size: 12px; color: var(--ok); }
.conn.off { color: var(--danger); }
.search { padding: 4px 12px 8px; }
.search input { border-radius: 999px; background: var(--bg-2); border-color: transparent; padding: 9px 14px; }
#conv-list { flex: 1; overflow-y: auto; padding: 0 6px 12px; }
.conv { width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px; border: 0; background: none; border-radius: 14px;
  cursor: pointer; text-align: left; }
.conv:hover { background: var(--bg-2); }
.conv.active { background: var(--accent-soft); }
.conv-main { flex: 1; min-width: 0; }
.conv-top, .conv-bottom { display: flex; align-items: center; gap: 8px; }
.conv-top strong { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv-time { font-size: 12px; color: var(--muted); }
.conv-prev { flex: 1; color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--accent); color: #fff; border-radius: 999px; font-size: 12px; min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center; font-weight: 600; }
.list-sep { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 14px 12px 4px; }
.conv.pending { cursor: default; }
.empty-list { text-align: center; color: var(--muted); padding: 40px 20px; }
.avatar { width: 44px; height: 44px; border-radius: 50%; flex: none; display: grid; place-items: center; color: #fff;
  font-weight: 600; font-size: 16px; background: var(--accent); user-select: none; }
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }
.avatar.huge { width: 96px; height: 96px; font-size: 34px; }
.avatar.huge .ic { width: 44px; height: 44px; }
.avatar.center { margin: 0 auto 8px; }
.avatar.pend { background: var(--bg-3); color: var(--muted); }
#me-avatar { width: 36px; height: 36px; font-size: 14px; }

/* discussion */
#chat { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
#chat-empty { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; gap: 4px; padding: 20px; }
#chat-empty h2 { margin: 12px 0 0; }
#chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 6px; padding: 8px 10px; border-bottom: 1px solid var(--line); }
.chat-head .avatar { width: 38px; height: 38px; font-size: 14px; }
.chat-head .back { display: none; }
.chat-title { flex: 1; min-width: 0; text-align: left; border: 0; background: none; cursor: pointer; display: flex; flex-direction: column; padding: 2px 6px; }
.chat-title strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-title span { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#messages { flex: 1; overflow-y: auto; padding: 12px 14px 8px; display: flex; flex-direction: column; gap: 3px; }
.e2e-note { align-self: center; max-width: 420px; text-align: center; font-size: 12.5px; color: var(--muted); background: var(--bg-2);
  padding: 8px 12px; border-radius: 12px; margin: 6px 0 10px; }
.day { align-self: center; margin: 10px 0 6px; }
.day span { font-size: 12px; color: var(--muted); background: var(--bg-2); padding: 3px 10px; border-radius: 999px; }
.sys { align-self: center; text-align: center; font-size: 13px; color: var(--muted); max-width: 80%; margin: 6px 0; }
.msg { display: flex; }
.msg.out { justify-content: flex-end; }
.bubble { max-width: min(72%, 560px); padding: 8px 12px 6px; border-radius: var(--radius); background: var(--in); color: var(--in-fg);
  word-wrap: break-word; overflow-wrap: anywhere; cursor: default; }
.msg.out .bubble { background: var(--out); color: var(--out-fg); }
.msg.in .bubble { border-bottom-left-radius: 6px; }
.msg.out .bubble { border-bottom-right-radius: 6px; }
.bubble.deleted { font-style: italic; opacity: .75; }
.bubble.media { padding: 4px 4px 6px; }
.bubble .text { white-space: pre-wrap; }
.bubble a { color: inherit; text-decoration: underline; }
.from { font-size: 13px; font-weight: 600; margin-bottom: 2px; }
.meta { display: flex; align-items: center; justify-content: flex-end; gap: 3px; font-size: 11.5px; opacity: .72; margin-top: 2px; padding: 0 4px; }
.st { display: inline-flex; margin-left: 2px; }
.st .ic { width: 14px; height: 14px; }
.st .ic.second { margin-left: -8px; }
.st.read { color: #9fe3ff; opacity: 1; }
.st.failed { color: #ffb4ab; }
.file-wrap img { display: block; max-width: 100%; max-height: 360px; border-radius: 14px; cursor: zoom-in; }
.file-wrap audio { width: 260px; max-width: 100%; display: block; }
.file { display: flex; align-items: center; gap: 10px; background: rgba(127,127,127,.15); border: 0; border-radius: 12px; padding: 10px 12px;
  cursor: pointer; text-align: left; min-width: 200px; color: inherit; }
.file.loading { cursor: default; font-size: 13px; opacity: .8; min-height: 60px; }
.file.error { cursor: default; font-size: 13px; }
.fname { flex: 1; display: flex; flex-direction: column; min-width: 0; }
.fname strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 500; }
.fname small { opacity: .75; }
#invite-bar { border-top: 1px solid var(--line); padding: 12px 16px; text-align: center; }
#invite-bar p { margin: 0 0 10px; }
.row { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

/* barre de saisie */
.composer { padding: 8px 10px calc(8px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
#compose-bar, #rec-bar { display: flex; align-items: flex-end; gap: 6px; }
#rec-bar { align-items: center; }
#input { flex: 1; resize: none; border-radius: 22px; background: var(--bg-2); border-color: transparent; padding: 10px 16px; max-height: 160px; line-height: 1.35; }
.rec-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }

/* modale */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: grid; place-items: center; z-index: 20; padding: 16px; }
.modal-card { width: min(460px, 100%); max-height: 90dvh; overflow: auto; background: var(--bg); border-radius: 22px; box-shadow: var(--shadow); padding: 8px 20px 20px; }
.modal[data-kind=image] .modal-card { width: min(900px, 100%); }
.modal-card header { display: flex; align-items: center; justify-content: space-between; position: sticky; top: 0; background: var(--bg); padding: 8px 0; z-index: 1; }
.modal-card h3 { margin: 0; font-size: 18px; }
#modal-body { display: flex; flex-direction: column; gap: 12px; }
#modal-body h4 { margin: 10px 0 0; font-size: 14px; display: flex; align-items: center; gap: 6px; }
#modal-body hr { border: 0; border-top: 1px solid var(--line); width: 100%; margin: 6px 0; }
#modal-body p { margin: 0; }
.menu-list { display: flex; flex-direction: column; gap: 4px; }
.menu-item { display: flex; align-items: center; gap: 14px; padding: 12px; border: 0; background: none; border-radius: 14px; cursor: pointer; text-align: left; width: 100%; }
.menu-item:hover { background: var(--bg-2); }
.menu-item.selected { background: var(--accent-soft); }
.menu-item > span:not(.ic) { flex: 1; display: flex; flex-direction: column; }
.menu-item small { color: var(--muted); }
.menu-item > .ic:first-child { color: var(--accent); }
.invite-box { display: flex; flex-direction: column; gap: 12px; align-items: stretch; }
.qr { width: min(280px, 100%); margin: 0 auto; background: #fff; border-radius: 16px; padding: 6px; }
.qr svg { display: block; width: 100%; height: auto; }
.link-field { font-family: ui-monospace, monospace; font-size: 12px; word-break: break-all; }
.code { font-family: ui-monospace, "SF Mono", monospace; font-size: 18px; letter-spacing: .04em; line-height: 1.7; text-align: center;
  background: var(--bg-2); border-radius: 14px; padding: 12px; word-spacing: .4em; }
.pick-list, .members { display: flex; flex-direction: column; gap: 2px; max-height: 300px; overflow: auto; }
.pick, .member { flex-direction: row !important; align-items: center; gap: 10px; padding: 8px; border-radius: 12px; color: var(--fg) !important; display: flex; }
.pick { cursor: pointer; }
.pick:hover { background: var(--bg-2); }
.tag { font-size: 11px; background: var(--accent-soft); color: var(--accent); padding: 2px 8px; border-radius: 999px; }
.scan-area video { width: 100%; border-radius: 14px; }
.full-img { width: 100%; border-radius: 12px; }

/* menu contextuel */
#ctx-menu { position: fixed; z-index: 30; background: var(--bg); border-radius: 14px; box-shadow: var(--shadow); padding: 6px; min-width: 220px; display: flex; flex-direction: column; }
#ctx-menu button { border: 0; background: none; text-align: left; padding: 10px 12px; border-radius: 10px; cursor: pointer; }
#ctx-menu button:hover { background: var(--bg-2); }

/* appel */
#call { position: fixed; inset: 0; z-index: 40; background: #0d0f14; color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: 60px 20px calc(40px + env(safe-area-inset-bottom)); }
#remote-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; }
#call.video #remote-video { display: block; }
#local-video { position: absolute; right: 16px; top: 16px; width: 120px; border-radius: 14px; z-index: 2; object-fit: cover; aspect-ratio: 3/4; background: #222; }
.call-info { position: relative; z-index: 1; text-align: center; text-shadow: 0 1px 6px rgba(0,0,0,.6); }
#call.video .call-info .avatar { display: none; }
.call-info h2 { margin: 16px 0 4px; }
.call-info p { margin: 0; opacity: .8; }
.call-actions { position: relative; z-index: 1; display: flex; gap: 28px; }
.round { width: 64px; height: 64px; border-radius: 50%; border: 0; background: rgba(255,255,255,.16); color: #fff; display: grid; place-items: center; cursor: pointer; }
.round .ic { width: 28px; height: 28px; }
.round.off { background: #fff; color: #111; }
.round.danger { background: var(--danger); }
.round.danger .ic { transform: rotate(135deg); }
.round.ok { background: var(--ok); }

/* toast */
#toast { position: fixed; left: 50%; bottom: 90px; transform: translateX(-50%) translateY(20px); background: #222; color: #fff; padding: 10px 18px;
  border-radius: 999px; font-size: 14px; opacity: 0; pointer-events: none; transition: .2s; z-index: 50; max-width: 90vw; text-align: center; }
#toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }

/* mobile : un seul panneau à la fois */
@media (max-width: 760px) {
  #sidebar { width: 100%; border-right: 0; }
  #chat { display: none; }
  #app.show-chat #sidebar { display: none; }
  #app.show-chat #chat { display: flex; }
  .chat-head .back { display: inline-grid; }
  .bubble { max-width: 84%; }
}
