:root {
  --bg: #0b0b0c;
  --panel: #151517;
  --panel-2: #1d1d20;
  --line: #2a2a2e;
  --text: #ecebe8;
  --muted: #8d8c88;
  --red: #c8102e;
  --red-2: #e3243f;
  --mine: #5a0b17;
  --theirs: #1f1f23;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Arial, sans-serif; }
body { overscroll-behavior: none; }
[hidden] { display: none !important; }
button, input, textarea { font: inherit; color: inherit; }

.screen { position: fixed; inset: 0; display: flex; flex-direction: column; background: var(--bg); }

/* Barre du haut */
.bar { display: flex; align-items: center; gap: 10px; padding: calc(10px + var(--safe-top)) 14px 10px;
  background: rgba(11,11,12,.92); border-bottom: 1px solid var(--line); backdrop-filter: blur(12px); }
.bar h2 { flex: 1; margin: 0; font-size: 18px; font-weight: 600; letter-spacing: .02em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo-small { width: 28px; height: 28px; }
.icon-btn { background: none; border: 0; padding: 6px 8px; font-size: 22px; line-height: 1; color: var(--text); cursor: pointer; }
.icon-btn.shield { color: var(--muted); font-size: 18px; }
.icon-btn.shield.verified { color: var(--red-2); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #555; }
.dot.on { background: #2ecc71; }

/* Accueil */
.welcome { flex: 1; overflow-y: auto; padding: calc(40px + var(--safe-top)) 22px 30px; display: flex; flex-direction: column; align-items: center; }
.logo-big { width: 110px; height: 110px; margin-bottom: 8px; }
.welcome h1 { margin: 4px 0 0; font-size: 34px; letter-spacing: .12em; text-transform: uppercase; font-weight: 700; }
.tagline { color: var(--muted); margin: 4px 0 26px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 16px; width: 100%; max-width: 440px; margin: 0 auto 14px; }
.card h3 { margin: 0 0 6px; font-size: 16px; }
.pad { padding: 16px; overflow-y: auto; flex: 1; }
.card.pad { flex: none; margin-top: 16px; }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 14px; }
input, textarea { display: block; width: 100%; margin-top: 6px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); outline: none; font-size: 16px; }
input:focus, textarea:focus { border-color: var(--red); }
.btn { display: inline-block; border: 1px solid var(--line); background: var(--panel-2); border-radius: 10px; padding: 12px 16px; cursor: pointer; font-weight: 600; }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; width: 100%; }
.btn.primary:active { background: var(--red-2); }
.btn.danger { background: transparent; border-color: var(--red); color: var(--red-2); width: 100%; }
.btn.ghost { background: transparent; }
.btn.small { padding: 7px 12px; font-size: 14px; width: auto; }
.hint { color: var(--muted); font-size: 13px; margin: 10px 0 0; }
.hint.install { max-width: 440px; text-align: center; }
.error { color: var(--red-2); font-size: 14px; margin: 10px 0 0; }
.muted { color: var(--muted); margin: 0; font-size: 14px; }
.me { font-size: 22px; font-weight: 700; margin: 4px 0 0; }
.invite { display: flex; align-items: center; gap: 10px; margin-top: 12px; }
.invite code { flex: 1; font-size: 20px; letter-spacing: .08em; color: var(--red-2); font-family: ui-monospace, Menlo, monospace; }
.danger-zone { border-color: #3a1218; }

/* Liste */
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv-list li { display: flex; align-items: center; gap: 12px; padding: 12px 16px; border-bottom: 1px solid var(--line); cursor: pointer; }
.conv-list li:active { background: var(--panel); }
.avatar { width: 46px; height: 46px; flex: none; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line);
  display: grid; place-items: center; font-weight: 700; font-size: 18px; text-transform: uppercase; color: var(--red-2); }
.conv-main { flex: 1; min-width: 0; }
.conv-top { display: flex; justify-content: space-between; gap: 8px; }
.conv-name { font-weight: 600; }
.conv-time { color: var(--muted); font-size: 12px; }
.conv-last { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.badge { background: var(--red); color: #fff; border-radius: 10px; min-width: 20px; padding: 1px 6px; font-size: 12px; text-align: center; font-weight: 700; }
.empty { color: var(--muted); text-align: center; margin-top: 30vh; }
.fab { position: absolute; right: 20px; bottom: calc(24px + var(--safe-bottom)); width: 58px; height: 58px; border-radius: 50%;
  border: 0; background: var(--red); color: #fff; font-size: 28px; box-shadow: 0 6px 20px rgba(200,16,46,.35); cursor: pointer; }

/* Conversation */
.messages { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 4px; -webkit-overflow-scrolling: touch; }
.day { align-self: center; color: var(--muted); font-size: 12px; margin: 10px 0 6px; background: var(--panel); padding: 3px 10px; border-radius: 10px; }
.msg { max-width: 80%; padding: 8px 11px 6px; border-radius: 16px; word-wrap: break-word; white-space: pre-wrap; }
.msg.out { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 5px; }
.msg.in { align-self: flex-start; background: var(--theirs); border-bottom-left-radius: 5px; }
.msg img { display: block; max-width: 100%; max-height: 340px; border-radius: 10px; margin-bottom: 4px; }
.msg audio { display: block; width: 230px; max-width: 100%; margin-bottom: 2px; }
.msg .meta { display: block; text-align: right; font-size: 11px; color: rgba(236,235,232,.55); margin-top: 2px; }
.msg .meta .st.delivered { color: #ff6b81; }
.msg.err { opacity: .6; font-style: italic; }
.warning { background: #3a1218; color: #ffd5db; padding: 10px 14px; font-size: 14px; display: flex; flex-direction: column; gap: 8px; }

.composer { display: flex; align-items: flex-end; gap: 6px; padding: 8px 8px calc(8px + var(--safe-bottom)); border-top: 1px solid var(--line); background: var(--panel); }
.composer textarea { flex: 1; margin: 0; resize: none; max-height: 130px; border-radius: 20px; padding: 9px 14px; }
.composer .attach { font-size: 26px; color: var(--muted); margin: 0; }
.composer .send, .composer .mic { width: 40px; height: 40px; border-radius: 50%; background: var(--red); color: #fff; font-size: 18px; display: grid; place-items: center; padding: 0; flex: none; }
.recorder { align-items: center; justify-content: space-between; }
.rec-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--red-2); animation: pulse 1s infinite; }
#rec-time { flex: 1; font-variant-numeric: tabular-nums; }
@keyframes pulse { 50% { opacity: .3; } }

/* Code de sécurité */
dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 16px; padding: 20px; width: min(92vw, 420px); }
dialog::backdrop { background: rgba(0,0,0,.7); }
dialog h3 { margin: 0 0 6px; }
.safety { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin: 16px 0; font-family: ui-monospace, Menlo, monospace; font-size: 18px; text-align: center; }
.row { display: flex; gap: 8px; margin-top: 12px; }
.row .btn { flex: 1; }

.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: #222; border: 1px solid var(--line);
  padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 10; max-width: 90vw; text-align: center; }
