/* WX Messenger — вид как у Telegram: светлая и тёмная тема по системе, телефон — чаты и переписка по очереди */
:root {
  --bg: #fff; --side: #fff; --chat-bg: #e7ebf0; --line: #e3e6ea; --text: #0f1419; --muted: #707579; --accent: #3390ec;
  --mine: #e3fee0; --other: #fff; --mine-time: #5ca853; --hover: #f4f4f5; --on: #3390ec; --badge: #3390ec; --input: #f1f3f4;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #212121; --side: #212121; --chat-bg: #0f0f0f; --line: #2f2f2f; --text: #f5f5f5; --muted: #aaa; --accent: #8774e1;
    --mine: #766ac8; --other: #212121; --mine-time: #e0dcff; --hover: #2c2c2c; --on: #766ac8; --badge: #8774e1; --input: #181818; }
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
html { height: var(--app-h, 100%); overflow: hidden; }
body { position: fixed; left: 0; right: 0; top: var(--app-top, 0px); height: var(--app-h, 100%); }
.join { overflow-y: auto; height: 100%; }
body { background: var(--bg); color: var(--text); font: 15px/1.4 -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; overflow: hidden;
  /* iPhone: вырез и полоска «Домой» — содержимое не залезает под них (приложение с экрана «Домой») */
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left); }
/* iOS увеличивает страницу при вводе, если шрифт поля меньше 16px */
input, textarea, select { font-size: 16px; }
button { font: inherit; cursor: pointer; }
input, textarea { font: inherit; color: var(--text); }

.join { min-height: 100%; display: grid; place-items: center; padding: 16px; background: var(--chat-bg); }
body:has(.join) { background: var(--chat-bg); }
.join-card { width: min(400px, 100%); background: var(--bg); border-radius: 16px; padding: 32px 24px; text-align: center; box-shadow: 0 4px 24px rgba(0,0,0,.08); }
.join-card .logo { width: 88px; height: 88px; margin: 0 auto 12px; border-radius: 50%; background: var(--accent); color: #fff; display: grid; place-items: center; font: 700 30px/1 sans-serif; }
.join-card h1 { margin: 0 0 8px; font-size: 22px; }
.join-card p { color: var(--muted); margin: 0 0 16px; }
.join-card input { width: 100%; padding: 14px; border: 1px solid var(--line); border-radius: 12px; background: var(--input); text-align: center; font-size: 22px; letter-spacing: 3px; text-transform: uppercase; }
.join-card button { width: 100%; margin-top: 12px; padding: 14px; border: 0; border-radius: 12px; background: var(--accent); color: #fff; font-weight: 600; }
.join-card .err { color: #e53935; min-height: 1.4em; margin: 10px 0 0; }
.small { font-size: 13px; color: var(--muted); }

.app { display: grid; grid-template-columns: minmax(280px, 380px) minmax(0, 1fr); height: 100%; height: calc(var(--app-h, 100dvh) - env(safe-area-inset-top)); }
.side { display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--side); min-width: 0; }
.top { display: flex; align-items: center; gap: 8px; padding: 8px 12px; min-height: 56px; border-bottom: 1px solid var(--line); background: var(--bg); }
.icon { border: 0; background: none; color: var(--muted); font-size: 20px; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; flex: none; }
.icon:hover { background: var(--hover); }
.search { flex: 1; min-width: 0; padding: 9px 16px; border: 1px solid transparent; border-radius: 22px; background: var(--input); outline: none; }
.search:focus { border-color: var(--accent); background: var(--bg); }
.chats { flex: 1; overflow-y: auto; padding: 6px; }
.row { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 12px; cursor: pointer; }
.row:hover { background: var(--hover); }
.row.on { background: var(--on); color: #fff; }
.row.on .p span, .row.on time { color: rgba(255,255,255,.85); }
.ava { width: 54px; height: 54px; border-radius: 50%; color: #fff; display: grid; place-items: center; font-weight: 600; font-size: 18px; flex: none; }
.ava.sm { width: 40px; height: 40px; font-size: 15px; }
.mid { flex: 1; min-width: 0; }
.mid .t, .mid .p { display: flex; justify-content: space-between; gap: 8px; align-items: center; }
.mid b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mid time { font-size: 12px; color: var(--muted); flex: none; }
.mid .p span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }
.mid .p i { font-style: normal; background: var(--badge); color: #fff; border-radius: 12px; min-width: 22px; height: 22px; padding: 0 7px; font-size: 12px; font-weight: 600; display: grid; place-items: center; flex: none; }
.none { color: var(--muted); text-align: center; padding: 32px 16px; }
.me { padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; gap: 8px; }
.me span { font-size: 11px; opacity: .8; }

.chat { display: flex; flex-direction: column; min-width: 0; background: var(--chat-bg); }
.chat.empty { display: grid; place-items: center; }
.placeholder { background: rgba(0,0,0,.2); color: #fff; padding: 6px 14px; border-radius: 16px; font-size: 14px; }
.chat .back { display: none; }
.ttl { display: flex; flex-direction: column; min-width: 0; }
.ttl b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ttl small { color: var(--muted); }
.msgs { flex: 1; overflow-y: auto; padding: 12px max(12px, calc((100% - 760px) / 2)); display: flex; flex-direction: column; gap: 4px; }
.day { text-align: center; margin: 8px 0; }
.day span { background: rgba(0,0,0,.25); color: #fff; padding: 3px 10px; border-radius: 12px; font-size: 13px; }
.msg { display: flex; }
.msg.mine { justify-content: flex-end; }
.bub { max-width: min(560px, 85%); background: var(--other); border-radius: 14px 14px 14px 4px; padding: 6px 10px 6px; box-shadow: 0 1px 1px rgba(0,0,0,.08); overflow-wrap: anywhere; position: relative; }
.mine .bub { background: var(--mine); border-radius: 14px 14px 4px 14px; }
.bub time { float: right; font-size: 11px; color: var(--muted); margin: 6px 0 -2px 10px; }
.mine .bub time { color: var(--mine-time); }
.who { display: block; font-size: 13px; margin-bottom: 2px; }
.txt a { color: var(--accent); }
.quote { border-left: 3px solid var(--accent); padding: 2px 8px; margin-bottom: 4px; font-size: 13px; background: rgba(51,144,236,.08); border-radius: 4px; display: flex; flex-direction: column; }
.quote span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.img { min-width: 120px; min-height: 80px; display: grid; place-items: center; color: var(--muted); cursor: zoom-in; }
.img img { display: block; max-width: 100%; max-height: 360px; border-radius: 10px; }
.file { display: flex; gap: 10px; align-items: center; color: inherit; text-decoration: none; }
.file .fi { width: 44px; height: 44px; border-radius: 50%; background: var(--accent); display: grid; place-items: center; font-size: 20px; flex: none; }
.file small { display: block; color: var(--muted); }
.reply-bar[hidden] { display: none; }
.reply-bar { display: flex; gap: 8px; align-items: center; padding: 6px 12px; background: var(--bg); border-top: 1px solid var(--line); }
.reply-bar div { flex: 1; min-width: 0; border-left: 3px solid var(--accent); padding-left: 8px; display: flex; flex-direction: column; font-size: 13px; }
.reply-bar span { color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.compose { display: flex; align-items: flex-end; gap: 6px; padding: 8px max(8px, calc((100% - 776px) / 2)); padding-bottom: max(8px, env(safe-area-inset-bottom)); background: var(--bg); border-top: 1px solid var(--line); }
.compose textarea { flex: 1; min-width: 0; resize: none; border: 0; outline: none; background: var(--input); border-radius: 20px; padding: 10px 14px; max-height: 160px; }
.compose .send { color: var(--accent); }
.attach { cursor: pointer; }

.modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; padding: 16px; z-index: 10; }
.modal { width: min(440px, 100%); max-height: 86vh; overflow-y: auto; background: var(--bg); border-radius: 16px; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
.modal h2 { margin: 0; font-size: 19px; overflow-wrap: anywhere; }
.modal .search { flex: none; }
.gname { padding: 10px 14px; border: 1px solid var(--line); border-radius: 10px; background: var(--input); }
.people { display: flex; flex-direction: column; gap: 2px; max-height: 50vh; overflow-y: auto; }
.person { display: flex; gap: 10px; align-items: center; padding: 6px 8px; border-radius: 10px; cursor: pointer; }
.person:hover { background: var(--hover); }
.person span { display: flex; flex-direction: column; min-width: 0; }
.person small { color: var(--muted); }
.actions { display: flex; justify-content: flex-end; gap: 8px; }
.actions button, .wide { border: 0; border-radius: 10px; padding: 10px 16px; background: var(--hover); color: var(--text); }
.actions .ok { background: var(--accent); color: #fff; }
.code { font-size: 22px; letter-spacing: 2px; color: var(--text); }
.toast { position: fixed; left: 50%; bottom: 80px; transform: translateX(-50%); background: rgba(0,0,0,.8); color: #fff; padding: 8px 14px; border-radius: 10px; z-index: 20; max-width: calc(100% - 32px); }
.test-note { position: fixed; right: 8px; bottom: 4px; font-size: 11px; color: var(--muted); pointer-events: none; opacity: .7; }

@media (max-width: 760px) {
  .app { grid-template-columns: minmax(0, 1fr); }
  .app .chat, .app .chat.empty { display: none; }
  .in-chat .side { display: none; }
  .in-chat .app .chat { display: flex; }
  .chat .back { display: grid; }
  .test-note { display: none; }
}

.ios-hint { text-align: left; background: #fff7e0; color: #5c4400; border-radius: 12px; padding: 12px 14px; margin-bottom: 16px; font-size: 14px; }
.ios-hint ol { margin: 6px 0; padding-left: 20px; }
.ios-hint small { color: #7a6200; }
.ios-hint .share { display: inline-block; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; font-size: 12px; }
@media (prefers-color-scheme: dark) { .ios-hint { background: #3a3220; color: #f3e2b3; } .ios-hint small { color: #d9c690; } }

.sys { text-align: center; margin: 6px 0; }
.sys span { background: rgba(0,0,0,.18); color: #fff; padding: 3px 10px; border-radius: 12px; font-size: 13px; }
.left-note { padding: 14px; text-align: center; color: var(--muted); background: var(--bg); border-top: 1px solid var(--line); }
.rename { display: flex; gap: 8px; } .rename .gname { flex: 1; min-width: 0; }
.person .rm { margin-left: auto; width: 32px; height: 32px; font-size: 14px; }
.actions .leave { color: #e53935; }

.profile { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 6px; }
.ava.big { width: 88px; height: 88px; font-size: 30px; }
.profile .about { margin: 0; color: var(--text); font-style: italic; }
.profile dl { display: grid; grid-template-columns: auto minmax(0, 1fr); gap: 6px 12px; text-align: left; width: 100%; margin: 8px 0 0; }
.profile dt { color: var(--muted); } .profile dd { margin: 0; overflow-wrap: anywhere; } .profile a { color: var(--accent); }
.fld { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.fld input { padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--input); color: var(--text); }
.who, .people .person span { cursor: pointer; }
.fld .ro { color: var(--text); font-size: 15px; padding: 4px 0; }

.ctx-wrap { position: fixed; inset: 0; z-index: 30; background: rgba(0,0,0,.25); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.ctx { position: fixed; display: flex; flex-direction: column; gap: 8px; max-width: calc(100vw - 16px); }
.rbar { display: flex; gap: 2px; background: var(--bg); border-radius: 28px; padding: 6px 8px; box-shadow: 0 4px 20px rgba(0,0,0,.15); overflow-x: auto; }
.rbar button { border: 0; background: none; font-size: 26px; padding: 2px 4px; border-radius: 50%; }
.items { display: flex; flex-direction: column; background: var(--bg); border-radius: 14px; box-shadow: 0 4px 20px rgba(0,0,0,.15); overflow: hidden; min-width: 220px; align-self: flex-start; }
.items button { border: 0; background: none; text-align: left; padding: 12px 16px; font-size: 16px; color: var(--text); display: flex; align-items: center; gap: 14px; }
.items button svg { flex: none; opacity: .75; }
.items button + button { border-top: 1px solid var(--line); }
.items .danger { color: #e53935; }
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.rx { border: 0; border-radius: 12px; padding: 2px 8px; font-size: 13px; background: rgba(51,144,236,.12); color: var(--text); }
.rx.on { background: var(--accent); color: #fff; }
.txt.del { font-style: italic; color: var(--muted); }
.fwd { font-size: 13px; color: var(--accent); margin-bottom: 2px; }
.pinned { display: flex; flex-direction: column; padding: 6px 14px; background: var(--bg); border-bottom: 1px solid var(--line); border-left: 3px solid var(--accent); cursor: pointer; font-size: 13px; }
.pinned[hidden] { display: none; }
.pinned b { color: var(--accent); } .pinned span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.msg.flash .bub { box-shadow: 0 0 0 3px var(--accent); transition: box-shadow .3s; }
.fwd-to { border: 0; background: none; width: 100%; text-align: left; color: var(--text); }
.msg { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* Долгое нажатие на iPhone не выделяет текст и эмодзи в меню */
.ctx-wrap, .ctx-wrap *, .rx, .chats, .top { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
