/* Nous — interface. Thème chaud, clair/sombre automatique. */
:root {
  --accent: #e8536b;
  --accent-2: #f08a5d;
  --accent-soft: color-mix(in srgb, var(--accent) 15%, transparent);
  --bubble-r: 14px;
  --wall-img: none;
  --wall-size: auto;
  --bg: #fbf6f4;
  --panel: #ffffff;
  --panel-2: #f4ecea;
  --text: #2a1f22;
  --muted: #8a7a7e;
  --line: rgba(42, 31, 34, .09);
  --bubble-in: #ffffff;
  --bubble-out: #ffe3e2;
  --bubble-out-text: #2a1f22;
  --shadow: 0 1px 1.5px rgba(42, 31, 34, .12);
  --wall: #f3e9e6;
  --danger: #e5484d;
  --ok: #30a46c;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #15100f; --panel: #1f1719; --panel-2: #2a2023; --text: #f4e9e9; --muted: #a8969a;
  --line: rgba(255, 235, 235, .08); --bubble-in: #2a2023;
  --shadow: 0 1px 1.5px rgba(0, 0, 0, .4); --wall: #120d0e; color-scheme: dark;
}
:root[data-theme="amoled"] {
  --bg: #000; --panel: #0b0809; --panel-2: #191314; --text: #f4e9e9; --muted: #9a898d;
  --line: rgba(255, 235, 235, .08); --bubble-in: #1a1416;
  --shadow: none; --wall: #000; color-scheme: dark;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { font: var(--fs, 15.5px)/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif; overflow: hidden; overscroll-behavior: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
svg { width: 22px; height: 22px; display: block; }
svg.i { fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
#app { height: 100%; height: var(--app-h, 100dvh); overflow: hidden; }

/* ---------- Auth ---------- */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; background:
  radial-gradient(1200px 600px at 20% -10%, color-mix(in srgb, var(--accent-2) 28%, transparent), transparent 60%),
  radial-gradient(900px 500px at 110% 110%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 60%), var(--bg); }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border-radius: 24px; padding: 32px 28px; box-shadow: 0 20px 60px rgba(42, 31, 34, .12); }
.logo { width: 64px; height: 64px; margin: 0 auto 12px; }
.auth h1 { text-align: center; margin: 0 0 4px; font-size: 28px; letter-spacing: -.02em; }
.auth p.sub { text-align: center; color: var(--muted); margin: 0 0 24px; }
.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin: 0 0 6px 4px; }
.field input, .field textarea { width: 100%; padding: 13px 14px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-2); outline: none; }
.field input:focus, .field textarea:focus { border-color: var(--accent); }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%; padding: 14px; border-radius: 14px; font-weight: 600;
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); color: #fff; }
.btn:disabled { opacity: .6; }
.btn.ghost { background: var(--panel-2); color: var(--text); }
.btn.danger { background: var(--danger); }
.link { color: var(--accent); font-weight: 600; }
.auth .switch { text-align: center; margin-top: 18px; color: var(--muted); font-size: 14px; }
.error { color: var(--danger); font-size: 14px; min-height: 20px; margin: 4px 4px 10px; }

/* ---------- Layout ---------- */
.layout { display: grid; grid-template-columns: 360px 1fr; grid-template-rows: minmax(0, 1fr); height: 100%; }
.sidebar, .chat-pane { min-height: 0; }
.contacts { min-height: 0; }
.sidebar { background: var(--panel); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 12px; padding: calc(10px + var(--safe-top)) 14px 10px; min-height: 60px; background: var(--panel); border-bottom: 1px solid var(--line); }
.topbar h2 { margin: 0; font-size: 21px; flex: 1; letter-spacing: -.01em; }
.icon-btn { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; color: var(--muted); flex: none; }
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.contacts { overflow-y: auto; flex: 1; }
.contact { display: flex; align-items: center; gap: 12px; padding: 12px 14px; cursor: pointer; }
.contact:hover, .contact.active { background: var(--panel-2); }
.contact .meta { flex: 1; min-width: 0; }
.contact .row { display: flex; align-items: baseline; gap: 8px; }
.contact .name { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.contact .time { font-size: 12px; color: var(--muted); }
.contact .preview { color: var(--muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.badge { background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: grid; place-items: center; }
.contact.unread .time { color: var(--accent); font-weight: 600; }
.empty { padding: 40px 24px; text-align: center; color: var(--muted); }

.avatar { width: 46px; height: 46px; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 700; color: #fff; font-size: 18px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent)); background-size: cover; background-position: center; position: relative; }
.avatar.sm { width: 40px; height: 40px; font-size: 16px; }
.avatar .dot { position: absolute; right: 0; bottom: 0; width: 12px; height: 12px; border-radius: 50%; background: var(--ok); border: 2px solid var(--panel); }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; min-width: 0; height: 100%; position: relative;
  background-color: var(--wall); background-image: var(--wall-img); background-size: var(--wall-size); background-position: center; }
.chat .topbar .who { flex: 1; min-width: 0; cursor: pointer; }
.chat .topbar .who .name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat .topbar .who .status { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat .topbar .who .status.typing { color: var(--accent); }
.messages { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 12px 4% 8px; display: flex; flex-direction: column; gap: 2px; overscroll-behavior: contain; }
.day { align-self: center; background: var(--panel); color: var(--muted); font-size: 12.5px; padding: 5px 12px; border-radius: 10px; margin: 10px 0 6px; box-shadow: var(--shadow); }
.msg { display: flex; max-width: min(78%, 560px); position: relative; touch-action: pan-y; }
.msg.out { align-self: flex-end; }
.msg.in { align-self: flex-start; }
.msg.grouped { margin-top: 0; }
.msg:not(.grouped) { margin-top: 6px; }
.bubble { padding: 6px 9px 6px; border-radius: var(--bubble-r); background: var(--bubble-in); box-shadow: var(--shadow); position: relative; min-width: 72px; word-wrap: break-word; overflow-wrap: anywhere; transition: transform .15s; }
.msg.out .bubble { background: var(--bubble-out); color: var(--bubble-out-text); }
.msg.in:not(.grouped) .bubble { border-top-left-radius: 4px; }
.msg.out:not(.grouped) .bubble { border-top-right-radius: 4px; }
.bubble .text { white-space: pre-wrap; }
.bubble .text.big { font-size: 40px; line-height: 1.15; }
.bubble.emoji-only { background: transparent !important; box-shadow: none; padding: 0 2px; }
.bubble .foot { float: right; margin: 6px 0 -4px 10px; font-size: 11.5px; color: var(--muted); display: inline-flex; align-items: center; gap: 3px; position: relative; top: 4px; }
.msg.out .bubble .foot { color: color-mix(in srgb, var(--bubble-out-text) 55%, transparent); }
.ticks { font-size: 12px; letter-spacing: -3px; margin-right: 3px; }
.ticks.read { color: #4fb3ff; }
.bubble .deleted { font-style: italic; color: var(--muted); }
.bubble img.media, .bubble video.media { display: block; max-width: 100%; width: 320px; max-height: 420px; object-fit: cover; border-radius: 8px; margin: -2px -4px 4px; width: calc(100% + 8px); min-width: 220px; background: var(--panel-2); cursor: zoom-in; }
.bubble video.media { cursor: default; }
.bubble audio { width: 250px; max-width: 100%; height: 40px; display: block; }
.bubble .file { display: flex; gap: 8px; align-items: center; padding: 6px 2px; color: inherit; text-decoration: none; }
.quote { border-left: 4px solid var(--accent); background: rgba(0, 0, 0, .05); border-radius: 6px; padding: 5px 8px; margin: 0 -3px 5px; font-size: 13.5px; cursor: pointer; max-height: 70px; overflow: hidden; }
.quote .who { color: var(--accent); font-weight: 600; font-size: 13px; }
.quote .what { color: var(--muted); overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.reactions { position: absolute; bottom: -14px; display: flex; gap: 1px; background: var(--panel); border-radius: 12px; padding: 1px 5px; box-shadow: 0 1px 3px rgba(0, 0, 0, .18); font-size: 14px; cursor: pointer; z-index: 1; }
.msg.out .reactions { right: 8px; }
.msg.in .reactions { left: 8px; }
.reactions .count { font-size: 12px; color: var(--muted); margin-left: 2px; align-self: center; }
.msg.has-reactions { margin-bottom: 14px; }
.msg.flash .bubble { animation: flash 1.2s; }
@keyframes flash { 0%, 60% { box-shadow: 0 0 0 4px var(--accent-soft); } }
.swipe-hint { position: absolute; left: -36px; top: 50%; transform: translateY(-50%) scale(.6); opacity: 0; color: var(--muted); }
.call-line { display: flex; align-items: center; gap: 10px; padding: 3px 2px; }
.call-line .ico { width: 36px; height: 36px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; }
.call-line .ico svg { width: 18px; height: 18px; }
.call-line.missed .ico { color: var(--danger); background: rgba(229, 72, 77, .12); }
.call-line .t { font-weight: 600; }
.call-line .s { font-size: 13px; color: var(--muted); }

.fab-down { position: absolute; right: 18px; bottom: 82px; width: 42px; height: 42px; border-radius: 50%; background: var(--panel); box-shadow: 0 2px 8px rgba(0, 0, 0, .2); display: grid; place-items: center; color: var(--muted); transform: rotate(-90deg); }

/* ---------- Composer ---------- */
.composer-wrap { padding: 6px 8px calc(8px + var(--safe-bottom)); }
.reply-bar { display: flex; align-items: center; gap: 8px; background: var(--panel); border-radius: 14px 14px 0 0; padding: 8px 8px 4px 10px; margin: 0 52px 0 0; }
.reply-bar .quote { flex: 1; margin: 0; }
.composer { display: flex; align-items: flex-end; gap: 6px; }
.composer .box { flex: 1; display: flex; align-items: flex-end; background: var(--panel); border-radius: 24px; box-shadow: var(--shadow); padding: 2px 4px; min-height: 48px; }
.reply-bar:not(.hidden) + .composer .box { border-top-left-radius: 0; border-top-right-radius: 0; }
.composer textarea { flex: 1; border: 0; outline: none; background: transparent; resize: none; max-height: 140px; padding: 13px 4px; line-height: 1.35; }
.composer .icon-btn { width: 44px; height: 44px; }
.send { width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; color: #fff; flex: none; background: linear-gradient(135deg, var(--accent-2), var(--accent)); box-shadow: 0 2px 8px color-mix(in srgb, var(--accent) 45%, transparent); }
.send.recording { background: var(--danger); animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 10px rgba(229, 72, 77, .15); } }
.rec-bar { flex: 1; display: flex; align-items: center; gap: 10px; background: var(--panel); border-radius: 24px; padding: 0 8px 0 16px; min-height: 48px; box-shadow: var(--shadow); }
.rec-bar .redd { width: 10px; height: 10px; border-radius: 50%; background: var(--danger); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .2; } }
.rec-bar .time { flex: 1; font-variant-numeric: tabular-nums; }
.upload-progress { height: 3px; background: var(--accent); width: 0; transition: width .2s; border-radius: 2px; margin: 0 8px 4px; }

/* ---------- Emoji picker ---------- */
.emoji-panel { background: var(--panel); border-radius: 18px; box-shadow: 0 8px 30px rgba(0, 0, 0, .2); margin: 0 0 8px; height: 300px; display: flex; flex-direction: column; overflow: hidden; }
.emoji-tabs { display: flex; border-bottom: 1px solid var(--line); overflow-x: auto; }
.emoji-tabs button { flex: 1; padding: 8px 6px; font-size: 20px; opacity: .55; border-bottom: 2px solid transparent; }
.emoji-tabs button.on { opacity: 1; border-color: var(--accent); }
.emoji-grid { flex: 1; overflow-y: auto; display: grid; grid-template-columns: repeat(auto-fill, minmax(42px, 1fr)); padding: 6px; align-content: start; }
.emoji-grid button { font-size: 27px; height: 44px; border-radius: 10px; }
.emoji-grid button:hover { background: var(--panel-2); }

/* ---------- Menus ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(0, 0, 0, .25); }
.ctx { position: fixed; z-index: 51; display: flex; flex-direction: column; gap: 8px; align-items: flex-start; }
.react-bar { display: flex; gap: 2px; background: var(--panel); border-radius: 28px; padding: 6px 8px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); }
.react-bar button { font-size: 28px; width: 44px; height: 44px; border-radius: 50%; transition: transform .1s; }
.react-bar button:hover { transform: scale(1.2); }
.react-bar button.on { background: var(--accent-soft); }
.react-bar .plus { font-size: 22px; color: var(--muted); background: var(--panel-2); }
.menu { background: var(--panel); border-radius: 14px; box-shadow: 0 8px 30px rgba(0, 0, 0, .25); overflow: hidden; min-width: 200px; }
.menu button { display: flex; align-items: center; gap: 12px; width: 100%; padding: 12px 16px; text-align: left; }
.menu button:hover { background: var(--panel-2); }
.menu button svg { width: 20px; height: 20px; color: var(--muted); }
.menu button.danger { color: var(--danger); }
.menu button.danger svg { color: var(--danger); }

/* ---------- Feuilles (réglages, dialogues) ---------- */
.sheet-wrap { position: fixed; inset: 0; z-index: 60; background: rgba(0, 0, 0, .35); display: grid; place-items: center; padding: 16px; }
.sheet { width: 100%; max-width: 440px; max-height: 90vh; overflow-y: auto; background: var(--panel); border-radius: 22px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .3); }
.sheet h3 { margin: 0 0 16px; font-size: 19px; }
.sheet .row-btns { display: flex; gap: 10px; margin-top: 8px; }
.sheet .row-btns .btn { flex: 1; }
.sheet .section { margin: 18px 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.profile-head { display: flex; flex-direction: column; align-items: center; gap: 10px; margin-bottom: 14px; }
.profile-head .avatar { width: 96px; height: 96px; font-size: 38px; cursor: pointer; }
.seg { display: flex; background: var(--panel-2); border-radius: 12px; padding: 3px; }
.seg button { flex: 1; padding: 8px; border-radius: 10px; font-size: 14px; }
.seg button.on { background: var(--panel); box-shadow: var(--shadow); font-weight: 600; }
.nick-suggest { display: flex; flex-wrap: wrap; gap: 6px; margin: -4px 0 14px; }
.nick-suggest button { background: var(--panel-2); padding: 6px 10px; border-radius: 14px; font-size: 14px; }

/* ---------- Appel ---------- */
.call { position: fixed; inset: 0; z-index: 100; background: radial-gradient(800px 600px at 50% 20%, color-mix(in srgb, var(--accent) 45%, #120a0c), #0e0809); color: #fff; display: flex; flex-direction: column; align-items: center; justify-content: space-between; padding: calc(40px + var(--safe-top)) 20px calc(36px + var(--safe-bottom)); }
.call .remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; display: none; }
.call.has-video .remote { display: block; }
.call .local { position: absolute; right: 16px; top: calc(16px + var(--safe-top)); width: 110px; height: 160px; object-fit: cover; border-radius: 14px; background: #222; z-index: 2; box-shadow: 0 4px 18px rgba(0, 0, 0, .5); transform: scaleX(-1); }
.call .local.back { transform: none; }
.call-info { position: relative; z-index: 1; text-align: center; margin-top: 30px; }
.call.has-video .call-info { margin-top: 0; text-shadow: 0 1px 4px rgba(0, 0, 0, .6); }
.call.has-video .call-avatar { display: none; }
.call-avatar { width: 120px; height: 120px; margin: 0 auto 18px; border-radius: 50%; background: linear-gradient(135deg, var(--accent-2), var(--accent)); background-size: cover; background-position: center; display: grid; place-items: center; font-size: 48px; font-weight: 700; }
.call.ringing .call-avatar { animation: ring 1.6s infinite; }
@keyframes ring { 0% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--accent) 60%, transparent); } 100% { box-shadow: 0 0 0 40px transparent; } }
.call-name { font-size: 28px; font-weight: 600; }
.call-status { opacity: .8; margin-top: 6px; font-variant-numeric: tabular-nums; }
.call-actions { position: relative; z-index: 2; display: flex; gap: 22px; }
.cbtn { width: 64px; height: 64px; border-radius: 50%; background: rgba(255, 255, 255, .18); backdrop-filter: blur(8px); display: grid; place-items: center; color: #fff; }
.cbtn svg { width: 26px; height: 26px; }
.cbtn.off { background: #fff; color: #222; }
.cbtn.decline { background: var(--danger); }
.cbtn.accept { background: var(--ok); }

/* ---------- Divers ---------- */
.viewer { position: fixed; inset: 0; z-index: 90; background: rgba(0, 0, 0, .92); display: grid; place-items: center; }
.viewer img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-close { position: absolute; top: calc(12px + var(--safe-top)); right: 12px; color: #fff; font-size: 22px; width: 44px; height: 44px; z-index: 1; }
.toast { position: fixed; left: 50%; bottom: calc(90px + var(--safe-bottom)); transform: translateX(-50%); background: #2a1f22; color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 200; font-size: 14px; max-width: 90%; text-align: center; }
.placeholder { flex: 1; display: grid; place-items: center; text-align: center; color: var(--muted); padding: 24px; }
.placeholder .logo { width: 90px; height: 90px; opacity: .9; }
.conn { background: #b8860b; color: #fff; text-align: center; font-size: 13px; padding: 4px; }

@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .layout.in-chat .sidebar { display: none; }
  .layout:not(.in-chat) .chat-pane { display: none; }
  .msg { max-width: 85%; }
  .messages { padding: 10px 10px 6px; }
}
@media (min-width: 761px) { .only-mobile { display: none !important; } }

/* ---------- Personnalisation ---------- */
.tabs { display: flex; gap: 4px; background: var(--panel-2); border-radius: 14px; padding: 4px; margin: -4px 0 18px; position: sticky; top: -22px; z-index: 2; }
.tabs button { flex: 1; padding: 9px 6px; border-radius: 11px; font-size: 14px; font-weight: 600; color: var(--muted); }
.tabs button.on { background: var(--panel); color: var(--text); box-shadow: var(--shadow); }
.look-preview { position: relative; border-radius: 18px; overflow: hidden; height: 190px; display: flex; flex-direction: column; justify-content: flex-end; gap: 4px; padding: 12px; margin-bottom: 6px;
  background-color: var(--wall); background-image: var(--wall-img); background-size: var(--wall-size); background-position: center; border: 1px solid var(--line); }
.look-preview .msg { max-width: 80%; margin-top: 2px; }
.look-preview .bubble { cursor: default; }
.swatches { display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px; }
.swatch { aspect-ratio: 1; border-radius: 50%; position: relative; box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .25); }
.swatch.on::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 2.5px solid var(--text); }
.swatch.custom { background: conic-gradient(#f44, #fd4, #4f4, #4df, #44f, #f4f, #f44); overflow: hidden; }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; cursor: pointer; }
.walls { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.wall { height: 84px; border-radius: 14px; border: 2px solid var(--line); background-color: var(--wall); background-position: center; font-size: 12.5px; font-weight: 600; color: var(--text); display: flex; align-items: flex-end; justify-content: center; padding-bottom: 6px; text-shadow: 0 1px 2px var(--panel); }
.wall.on { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.slider { width: 100%; accent-color: var(--accent); margin: 4px 0 6px; }
.opt-label { display: flex; justify-content: space-between; font-size: 14px; color: var(--muted); margin: 14px 2px 6px; }
.sheet { position: relative; }
/* lisibilité dans mes bulles (dégradé, couleurs vives) */
.msg.out .quote { background: rgba(0, 0, 0, .12); border-left-color: currentColor; }
.msg.out .quote .who { color: inherit; opacity: .95; }
.msg.out .quote .what { color: inherit; opacity: .75; }
.msg.out .call-line .ico { background: rgba(255, 255, 255, .22); color: inherit; }
.msg.out .call-line .s { color: inherit; opacity: .75; }
