/* Все цвета и размеры — в переменных: под новый дизайн меняется в основном этот блок */
/* Палитра и шрифт — как на лендинге СВОЙГРАМ */
:root {
  --accent: #398cff;
  --accent-2: #4bd8ff;
  --accent-grad: linear-gradient(110deg, #078edb, #245ce8);
  --accent-text: #fff;
  --bg: #050914;
  --panel: #091329;
  --panel-2: #0c1930;
  --text: #f3f7ff;
  --muted: #9caac2;
  --border: rgba(94, 151, 232, .19);
  --hover: #0c1930;
  --active: #10284c;
  --bubble-in: #0f1f3b;
  --bubble-out: #1b4fc0;
  --chat-bg: #050914;
  --danger: #f47b84;
  --online: #43e3b1;
  --radius: 14px;
  --sidebar-w: 340px;
  --font: Manrope, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  font-size: 15px;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;

}
button, input, textarea { font: inherit; color: inherit; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
#app { height: 100dvh; }

/* ---------- Вход и профиль ---------- */
.auth {
  min-height: 100dvh; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(ellipse at 76% 22%, rgba(12,70,157,.25), transparent 40%),
              radial-gradient(ellipse at 14% 70%, rgba(10,50,116,.18), transparent 40%), var(--bg);
}
.card {
  width: 100%; max-width: 380px; background: var(--panel);
  border: 1px solid var(--border); border-radius: 20px; padding: 28px 24px;
}
.logo { display: flex; align-items: center; justify-content: center; gap: 10px; font-size: 24px; font-weight: 800; letter-spacing: -.7px; margin-bottom: 12px; color: var(--text); text-decoration: none; }
.logo img { width: 44px; height: 44px; border-radius: 11px; box-shadow: 0 0 18px rgba(43,136,255,.35); }
.logo .accent { color: #77baff; }
.to-site { display: block; text-align: center; margin-top: 18px; font-size: 13px; color: var(--muted); text-decoration: none; }
.to-site:hover { color: var(--text); }
.card h1 { font-size: 20px; margin: 8px 0 4px; }
.card p { margin: 0 0 16px; }
.card form { display: flex; flex-direction: column; gap: 12px; }
.card label { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
.card input {
  width: 100%; padding: 12px 14px; border: 1px solid var(--border);
  border-radius: 12px; background: var(--bg); outline: none;
}
.card input:focus { border-color: var(--accent); }
.code-input { font-size: 24px; letter-spacing: 8px; text-align: center; }
.input-prefix { display: flex; align-items: center; border: 1px solid var(--border); border-radius: 12px; background: var(--bg); }
.input-prefix:focus-within { border-color: var(--accent); }
.input-prefix span { padding-left: 14px; color: var(--muted); }
.input-prefix input { border: 0; background: transparent; padding-left: 2px; }
.btn {
  padding: 13px; border: 1px solid #34b8ff; border-radius: 12px; background: var(--accent-grad);
  box-shadow: 0 8px 28px #0875e33b;
  color: var(--accent-text); font-weight: 600; cursor: pointer;
}
.btn:disabled { opacity: .6; cursor: default; }
.btn-outline { display: block; text-align: center; text-decoration: none; margin-bottom: 10px; background: transparent; color: var(--accent); border: 1px solid var(--accent); box-shadow: none; }
.btn-danger-outline { width: 100%; background: transparent; color: var(--danger); border: 1px solid var(--danger); }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; }
.link:disabled { color: var(--muted); cursor: default; }
.row-between { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.profile-top { margin-bottom: 4px; }
.error { color: var(--danger); font-size: 14px; min-height: 0; }
.error:empty { display: none; }
#profile-extra { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--border); }

/* ---------- Основной экран ---------- */
.main { display: flex; height: 100dvh; }
.sidebar {
  width: var(--sidebar-w); flex-shrink: 0; display: flex; flex-direction: column;
  background: var(--panel); border-right: 1px solid var(--border);
}
.side-head { padding: 10px 12px; border-bottom: 1px solid var(--border); }
.me { display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 4px; border-radius: 10px; cursor: pointer; width: 100%; text-align: left; }
.me:hover { background: var(--hover); }
.me-text { display: flex; flex-direction: column; min-width: 0; }
.me-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-status { font-size: 12px; color: var(--muted); }
.search { padding: 10px 12px; }
.search input {
  width: 100%; padding: 9px 12px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--bg); outline: none;
}
.search input:focus { border-color: var(--accent); }
.list { flex: 1; overflow-y: auto; }
.list-title { padding: 10px 16px 4px; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.list-empty { padding: 24px 16px; color: var(--muted); text-align: center; }

.item { display: flex; align-items: center; gap: 12px; padding: 9px 12px; margin: 0 6px; border-radius: 12px; cursor: pointer; }
.item:hover { background: var(--hover); }
.item.active { background: var(--active); }
.item-body { flex: 1; min-width: 0; }
.item-top, .item-bottom { display: flex; align-items: center; gap: 6px; }
.item-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-time { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.item-text { flex: 1; color: var(--muted); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item-text .you { color: var(--text); }
.item-text.typing { color: var(--accent); }
.badge { background: var(--accent-grad); color: var(--accent-text); font-size: 12px; font-weight: 600; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: grid; place-items: center; }
.ticks { font-size: 12px; color: var(--muted); flex-shrink: 0; }
.ticks.read { color: var(--accent-2); }

.avatar {
  --h: 210;
  width: 44px; height: 44px; border-radius: 50%; flex-shrink: 0; position: relative;
  display: grid; place-items: center; color: #fff; font-weight: 600; font-size: 16px;
  background: hsl(var(--h) 55% 52%);
}
.avatar.sm { width: 38px; height: 38px; font-size: 14px; }
.avatar.online::after {
  content: ""; position: absolute; right: 0; bottom: 0; width: 12px; height: 12px;
  border-radius: 50%; background: var(--online); border: 2px solid var(--panel);
}

/* ---------- Чат ---------- */
.chat {
  flex: 1; min-width: 0; display: flex; flex-direction: column;
  background: radial-gradient(ellipse at 80% 10%, rgba(12,70,157,.16), transparent 45%), var(--chat-bg);
}
.chat-empty { flex: 1; display: grid; place-items: center; color: var(--muted); padding: 24px; text-align: center; }
.chat-view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px;
  background: var(--panel); border-bottom: 1px solid var(--border);
}
.peer { min-width: 0; }
.peer-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.peer-status { font-size: 13px; color: var(--muted); }
.peer-status.on { color: var(--accent); }
.icon-btn { background: none; border: 0; font-size: 22px; cursor: pointer; padding: 4px 8px; border-radius: 8px; color: var(--accent); }
.back { display: none; }

.messages { flex: 1; overflow-y: auto; padding: 12px 16px; display: flex; flex-direction: column; gap: 3px; }
.day { align-self: center; margin: 10px 0 6px; padding: 3px 10px; border-radius: 10px; font-size: 12px; background: var(--panel-2); color: var(--muted); }
.msg {
  max-width: min(560px, 80%); padding: 7px 10px 5px; border-radius: var(--radius);
  background: var(--bubble-in); align-self: flex-start; white-space: pre-wrap; overflow-wrap: anywhere;
  box-shadow: 0 1px 1px rgba(0,0,0,.05);
}
.msg.out { background: var(--bubble-out); align-self: flex-end; color: #fff; }
.msg.out .msg-meta { color: rgba(255,255,255,.7); }
.msg.out .msg-meta .ticks.read { color: var(--accent-2); }
.msg.group-start { margin-top: 6px; }
.msg-meta { float: right; margin: 6px 0 -2px 10px; font-size: 11px; color: var(--muted); display: inline-flex; gap: 3px; align-items: center; }
.msg-meta .ticks.read { color: var(--accent-2); }
.msg.error { cursor: pointer; }
.msg.error .msg-meta { color: var(--danger); }
.loading-older { align-self: center; font-size: 12px; color: var(--muted); padding: 6px; }

.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 14px calc(10px + env(safe-area-inset-bottom));
  background: var(--panel); border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; resize: none; max-height: 160px; padding: 10px 14px; border-radius: 20px;
  border: 1px solid var(--border); background: var(--bg); outline: none; line-height: 1.35;
}
.composer textarea:focus { border-color: var(--accent); }
.send {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: var(--accent-grad);
  color: var(--accent-text); font-size: 18px; cursor: pointer; flex-shrink: 0;
}

.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%);
  background: #16294a; border: 1px solid var(--border); color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  max-width: calc(100% - 32px); z-index: 10;
}

/* ---------- Телефон ---------- */
@media (max-width: 720px) {
  .sidebar { width: 100%; border-right: 0; }
  .chat { display: none; }
  .main.chat-open .sidebar { display: none; }
  .main.chat-open .chat { display: flex; }
  .back { display: block; }
  .msg { max-width: 85%; }
}

/* ---------- Список чатов в стиле макета с лендинга ---------- */
.app-heading { display: flex; align-items: center; gap: 9px; padding: 16px 16px 12px; }
.mini-shield { width: 30px; height: 30px; display: grid; place-items: center; }
.mini-shield img { width: 100%; height: 100%; border-radius: 8px; }
.app-title { font-size: 17px; font-weight: 800; letter-spacing: -.4px; }
.app-title .accent { color: #77baff; }
.conn { font-size: 12px; color: var(--muted); }
.compose {
  margin-left: auto; width: 34px; height: 34px; border-radius: 10px; border: 0; background: none;
  font-size: 22px; line-height: 1; color: #7cbcff; cursor: pointer;
}
.compose:hover { background: var(--hover); }

.search { position: relative; padding: 0 14px 4px; }
.search-ico { position: absolute; left: 26px; top: 50%; transform: translateY(-60%); color: #69b8ff; font-size: 18px; pointer-events: none; }
.search input { background: #111f34; border: 1px solid #1d3656; border-radius: 10px; padding: 10px 12px 10px 36px; }
.search input::placeholder { color: #72839f; }

.chat-tabs { display: flex; gap: 22px; padding: 12px 16px 0; border-bottom: 1px solid #1b2b41; }
.tab {
  background: none; border: 0; padding: 0 0 10px; font-size: 13px; font-weight: 600;
  color: #71829b; cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab.active { color: #6bc9ff; border-bottom-color: #2daaff; }

.list { padding-top: 2px; }
.item { margin: 0; border-radius: 0; padding: 11px 16px; position: relative; }
.item::after { content: ""; position: absolute; left: 72px; right: 16px; bottom: 0; border-bottom: 1px solid #17263a; }
.item:hover { background: rgba(17, 31, 52, .7); }
.item.active { background: var(--active); }
.item.active::after { display: none; }
.item .avatar { width: 46px; height: 46px; }
.item-name { font-weight: 700; }
.item-time { color: #64748b; }
.item-text { color: #8492a9; }
.badge { background: #247ef2; }

.avatar { background: linear-gradient(135deg, #3d9bff, #3242a9); font-weight: 800; }

.bottom-nav {
  display: flex; justify-content: space-around; align-items: center;
  height: 58px; padding-bottom: env(safe-area-inset-bottom); box-sizing: content-box;
  background: #07101f; border-top: 1px solid #1c2e47;
}
.bottom-nav button {
  display: flex; flex-direction: column; align-items: center; gap: 3px; flex: 1;
  background: none; border: 0; color: #7185a4; cursor: pointer; padding: 6px 0;
}
.bottom-nav .nav-ico { font-size: 18px; line-height: 1; }
.bottom-nav small { font-size: 11px; }
.bottom-nav .selected { color: #55baff; }

/* ---------- Выбор страны (код телефона) ---------- */
.phone-row { display: flex; gap: 8px; }
.phone-row input { flex: 1; min-width: 0; }
.cc-btn {
  display: flex; align-items: center; gap: 7px; flex-shrink: 0; padding: 0 12px;
  border: 1px solid var(--border); border-radius: 12px; background: var(--bg); cursor: pointer;
}
.cc-btn:hover, .cc-btn.open { border-color: var(--accent); }
.flag { width: 24px; height: 18px; border-radius: 3px; object-fit: cover; flex-shrink: 0; box-shadow: 0 0 0 1px rgba(255,255,255,.08); }
.caret { color: var(--muted); font-size: 12px; }
.cc-panel { border: 1px solid var(--border); border-radius: 12px; background: var(--panel-2); overflow: hidden; }
.cc-panel input { border: 0 !important; border-bottom: 1px solid var(--border) !important; border-radius: 0 !important; background: transparent !important; }
.cc-list { max-height: 260px; overflow-y: auto; }
.cc-item { display: flex; align-items: center; gap: 12px; width: 100%; padding: 10px 14px; border: 0; background: none; cursor: pointer; text-align: left; }
.cc-item:hover, .cc-item.active { background: var(--active); }
.cc-item .cc-name { flex: 1; }
.cc-item .cc-dial { color: var(--muted); }

/* ---------- Переключатель в настройках ---------- */
.switch-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; cursor: pointer; }
.switch-row > span { display: flex; flex-direction: column; gap: 3px; flex: 1; }
.switch-title { color: var(--text); font-size: 15px; }
.switch {
  appearance: none; -webkit-appearance: none; width: 46px; height: 26px; border-radius: 13px; flex-shrink: 0;
  background: var(--panel-2); border: 1px solid var(--border); position: relative; cursor: pointer; transition: background .2s;
}
.switch::after {
  content: ""; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%;
  background: #9caac2; transition: transform .2s, background .2s;
}
.switch:checked { background: #247ef2; border-color: #247ef2; }
.switch:checked::after { transform: translateX(20px); background: #fff; }

/* ---------- Цитата, меню сообщения, панель ответа/редактирования ---------- */
.msg { position: relative; }
.msg.flash { animation: flash 1.2s ease; }
@keyframes flash { 0%, 40% { box-shadow: 0 0 0 3px var(--accent-2); } 100% { box-shadow: none; } }
.quote {
  display: block; margin: 0 0 5px; padding: 3px 8px; border-left: 3px solid var(--accent-2);
  border-radius: 6px; background: rgba(255,255,255,.06); cursor: pointer; max-width: 100%;
}
.msg.out .quote { border-left-color: #fff; background: rgba(255,255,255,.12); }
.quote b { display: block; font-size: 13px; color: var(--accent-2); }
.msg.out .quote b { color: #fff; }
.quote span { display: block; font-size: 13px; opacity: .85; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.quote.deleted span { font-style: italic; opacity: .6; }
.edited { font-size: 11px; opacity: .8; }

.msg-menu {
  position: fixed; z-index: 20; min-width: 200px; padding: 6px; border-radius: 12px;
  background: var(--panel-2); border: 1px solid var(--border); box-shadow: 0 12px 32px rgba(0,0,0,.45);
}
.msg-menu button {
  display: flex; align-items: center; gap: 12px; width: 100%; padding: 9px 12px; border: 0; border-radius: 8px;
  background: none; cursor: pointer; text-align: left; font-size: 14px;
}
.msg-menu button:hover { background: var(--active); }
.msg-menu button.danger { color: var(--danger); }
.msg-menu .mi { width: 18px; text-align: center; opacity: .85; }

.compose-bar {
  display: flex; align-items: center; gap: 10px; padding: 8px 14px 0; background: var(--panel);
}
.cb-icon { color: var(--accent-2); font-size: 18px; }
.cb-body { flex: 1; min-width: 0; border-left: 2px solid var(--accent-2); padding-left: 10px; }
.cb-title { font-size: 13px; color: var(--accent-2); font-weight: 600; }
.cb-text { font-size: 13px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ---------- Фото профиля ---------- */
.avatar-edit { display: flex; align-items: center; gap: 16px; margin-bottom: 4px; }
.avatar.xl { width: 84px; height: 84px; font-size: 30px; }
.avatar.loading { opacity: .5; }
.avatar-actions { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; }
.avatar-actions .link { font-size: 14px; }
.link.danger { color: var(--danger); }

/* ---------- Фото и файлы в сообщениях ---------- */
.attach {
  width: 42px; height: 42px; border-radius: 50%; border: 0; background: none; font-size: 20px;
  cursor: pointer; flex-shrink: 0; opacity: .85;
}
.attach:hover { background: var(--hover); opacity: 1; }
.msg.has-att { padding: 4px 4px 5px; }

.msg.has-att .msg-meta { margin-right: 6px; }
.msg.has-att .quote { margin: 2px 2px 5px; }
.att-img-wrap { position: relative; display: block; margin-bottom: 4px; }
.att-img {
  display: block; max-width: min(320px, 100%); max-height: 360px; width: auto; height: auto;
  border-radius: 10px; cursor: zoom-in; background: rgba(255,255,255,.04);
}
.upl {
  position: absolute; inset: 0; display: grid; place-items: center; border-radius: 10px;
  background: rgba(0,0,0,.45); color: #fff; font-weight: 700; font-size: 15px;
}
.att-file {
  display: flex; align-items: center; gap: 12px; padding: 6px 8px 4px; min-width: 220px;
  color: inherit; text-decoration: none; border-radius: 10px;
}
a.att-file:hover { background: rgba(255,255,255,.06); }
.att-file .file-ico {
  width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; flex-shrink: 0;
  background: var(--accent-grad); color: #fff; font-size: 18px;
}
.msg.out .att-file .file-ico { background: rgba(255,255,255,.2); }
.att-file .file-info { min-width: 0; display: flex; flex-direction: column; }
.att-file .file-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.att-file .file-size { font-size: 12px; opacity: .75; }

.lightbox {
  position: fixed; inset: 0; z-index: 30; background: rgba(2,5,12,.94);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 16px;
}
.lightbox img { max-width: 100%; max-height: calc(100dvh - 90px); border-radius: 8px; }
.lightbox-bar { display: flex; gap: 24px; }
.lightbox-bar a, .lightbox-bar button { color: #fff; background: none; border: 0; font-size: 15px; cursor: pointer; text-decoration: none; }
.drop-hint {
  position: fixed; inset: 16px; z-index: 25; display: grid; place-items: center; pointer-events: none;
  border: 3px dashed var(--accent-2); border-radius: 20px; background: rgba(5,9,20,.75);
  color: var(--text); font-size: 20px; font-weight: 700;
}
.msg > .msg-text { display: inline; }

.msg.has-att > .msg-text { padding: 0 6px; }
.msg.has-img { max-width: min(328px, 85%); }
.msg.has-img .att-img { max-width: 100%; }

/* =====================================================================
   Интерфейс в стиле Telegram на iPhone (поверх базовых стилей)
   ===================================================================== */
:root {
  --ios-bar: rgba(13, 18, 30, .86);
  --ios-hair: rgba(255, 255, 255, .09);
  --ios-gray: #8d93a0;
  --ios-field: #161d2b;
  --ios-cell: #111827;
  --ios-blue: #3e88f7;
  --bubble-in: #1b2433;
  --bubble-out: #2b63de;
  --radius: 18px;
}
.ico { width: 24px; height: 24px; fill: currentColor; display: block; }

/* ---------- шапка «Чаты» ---------- */
.ios-nav {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center;
  height: 52px; padding: 0 8px 0 16px;
}
.nav-title { margin: 0; font-size: 17px; font-weight: 700; letter-spacing: -.2px; }
.nav-side { display: flex; align-items: center; min-width: 0; }
.nav-side.right { justify-content: flex-end; }
.nav-side .conn { font-size: 13px; color: var(--ios-gray); }
.nav-icon-btn {
  width: 40px; height: 40px; border: 0; border-radius: 50%; background: none; color: var(--ios-blue);
  display: grid; place-items: center; cursor: pointer;
}
.nav-icon-btn .ico { width: 23px; height: 23px; }
.nav-icon-btn:hover { background: var(--hover); }

/* ---------- поиск ---------- */
.search { padding: 2px 12px 8px; position: relative; }
.search .search-ico {
  position: absolute; left: 22px; top: 50%; transform: translateY(-58%);
  width: 18px; height: 18px; fill: var(--ios-gray); pointer-events: none;
}
.search input {
  height: 36px; padding: 0 12px 0 34px; border-radius: 10px; border: 0;
  background: var(--ios-field); font-size: 16px;
}
.search input::placeholder { color: var(--ios-gray); }
.search input:focus { box-shadow: 0 0 0 1px rgba(62,136,247,.5); }

.chat-tabs { padding: 4px 16px 0; border-bottom: 1px solid var(--ios-hair); }
.tab { font-size: 14px; }
.tab.active { color: var(--ios-blue); border-bottom-color: var(--ios-blue); }

/* ---------- строки чатов ---------- */
.sidebar { background: var(--bg); }
.item { padding: 7px 14px 7px 12px; gap: 11px; align-items: flex-start; }
.item .avatar { width: 58px; height: 58px; font-size: 21px; margin-top: 1px; }
.item::after { left: 82px; right: 0; border-bottom: 1px solid var(--ios-hair); }
.item-body { padding-top: 3px; }
.item-name { font-size: 16.5px; font-weight: 600; }
.item-time { font-size: 14px; color: var(--ios-gray); }
.item-bottom { align-items: flex-start; margin-top: 1px; }
.item-text {
  white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  font-size: 15px; line-height: 1.3; color: var(--ios-gray); min-height: 39px;
}
.item-text .you { color: var(--text); }
.badge { background: var(--ios-blue); min-width: 22px; height: 22px; border-radius: 11px; margin-top: 8px; }
.ticks.read, .item .ticks.read { color: var(--ios-blue); }
.list-title { color: var(--ios-gray); }

/* ---------- нижняя панель (таб-бар) ---------- */
.tabbar {
  display: flex; justify-content: space-around; padding: 6px 0 calc(6px + env(safe-area-inset-bottom));
  background: var(--ios-bar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--ios-hair);
}
.tabbar button {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; flex: 1;
  background: none; border: 0; color: var(--ios-gray); cursor: pointer; padding: 2px 0;
}
.tabbar .tab-ico { width: 27px; height: 27px; fill: currentColor; }
.tabbar small { font-size: 10.5px; font-weight: 500; }
.tabbar .selected { color: var(--ios-blue); }
.tab-badge, .back-badge {
  min-width: 19px; height: 19px; padding: 0 5px; border-radius: 10px; background: #ff3b30; color: #fff;
  font-size: 12px; font-weight: 600; display: grid; place-items: center;
}
.tab-badge { position: absolute; top: -1px; left: calc(50% + 6px); }
.tab-badge.hidden, .back-badge.hidden { display: none; }

/* ---------- шапка чата: «‹ Чаты» · имя по центру · аватар ---------- */
.chat-head {
  display: grid; grid-template-columns: 1fr auto 1fr; gap: 8px; align-items: center;
  height: 56px; padding: 0 12px 0 4px;
  background: var(--ios-bar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--ios-hair);
}
.back-btn {
  justify-self: start; display: flex; align-items: center; gap: 0; border: 0; background: none;
  color: var(--ios-blue); font-size: 17px; cursor: pointer; padding: 6px 4px; visibility: hidden;
}
.back-btn .ico { width: 30px; height: 30px; margin-right: -4px; }
.back-badge { margin-left: 6px; background: var(--ios-blue); }
.chat-head .peer { text-align: center; min-width: 0; }
.peer-name { font-size: 16.5px; font-weight: 600; }
.peer-status { font-size: 13px; color: var(--ios-gray); }
.peer-status.on { color: var(--ios-blue); }
.chat-head .avatar.sm { justify-self: end; width: 38px; height: 38px; font-size: 15px; }
.chat-head .avatar.online::after { width: 10px; height: 10px; }

/* ---------- фон переписки ---------- */
.chat {
  background:
    radial-gradient(rgba(120,170,255,.06) 1px, transparent 1.3px) 0 0 / 22px 22px,
    radial-gradient(ellipse at 15% 0%, rgba(43,99,222,.22), transparent 55%),
    radial-gradient(ellipse at 100% 100%, rgba(75,216,255,.10), transparent 50%),
    linear-gradient(170deg, #0a1426, #050914 70%);
}
.day {
  background: rgba(0,0,0,.35); color: #e8edf7; backdrop-filter: blur(8px);
  font-size: 13px; font-weight: 500; padding: 3px 11px; border-radius: 12px;
}

/* ---------- пузыри с «хвостиками» ---------- */
.messages { padding: 10px 14px; gap: 2px; }
.msg { border-radius: var(--radius); font-size: 16px; line-height: 1.32; box-shadow: none; padding: 6px 11px 6px 12px; }
.msg.group-start { margin-top: 7px; }
.msg.out { background: var(--bubble-out); }
.msg.group-end.out { border-bottom-right-radius: 5px; margin-right: 7px; }
.msg.group-end:not(.out) { border-bottom-left-radius: 5px; margin-left: 7px; }
.msg:not(.out):not(.group-end) { margin-left: 7px; }
.msg.out:not(.group-end) { margin-right: 7px; }
.msg.group-end::after {
  content: ""; position: absolute; bottom: 0; width: 10px; height: 17px;
  -webkit-mask: var(--tail) no-repeat; mask: var(--tail) no-repeat;
}
.msg.group-end.out::after {
  right: -7px; background: var(--bubble-out);
  --tail: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 17'><path d='M0 0v17h10C4.5 15.8 1 11.6 0 0z'/></svg>");
}
.msg.group-end:not(.out)::after {
  left: -7px; background: var(--bubble-in);
  --tail: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 17'><path d='M10 0v17H0C5.5 15.8 9 11.6 10 0z'/></svg>");
}
.msg-meta { font-size: 12px; margin-top: 7px; }
.msg.out .msg-meta { color: rgba(255,255,255,.65); }
.msg.out .msg-meta .ticks.read { color: #fff; }
.quote { border-left-width: 3px; border-radius: 6px; }

/* ---------- поле ввода ---------- */
.composer {
  align-items: flex-end; gap: 6px; padding: 6px 8px calc(6px + env(safe-area-inset-bottom));
  background: var(--ios-bar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-top: 1px solid var(--ios-hair);
}
.attach {
  width: 38px; height: 38px; color: var(--ios-gray); display: grid; place-items: center; opacity: 1;
}
.attach .ico { width: 26px; height: 26px; transform: rotate(45deg); }
.attach:hover { color: var(--ios-blue); background: none; }
.composer textarea {
  min-height: 36px; padding: 7px 14px; border-radius: 18px; font-size: 16px;
  background: #0b111d; border: 1px solid #263046;
}
.composer textarea:focus { border-color: #34508a; }
.send {
  width: 36px; height: 36px; background: var(--ios-blue); display: none; place-items: center; margin-bottom: 0;
}
.send .ico { width: 22px; height: 22px; fill: #fff; }
.composer.has-text .send { display: grid; }
.compose-bar { background: var(--ios-bar); border-top: 1px solid var(--ios-hair); padding-bottom: 6px; }
.compose-bar .icon-btn { color: var(--ios-gray); display: grid; place-items: center; }
.compose-bar .icon-btn .ico { width: 20px; height: 20px; }
.cb-icon, .cb-title { color: var(--ios-blue); }
.cb-body { border-left-color: var(--ios-blue); }

/* ---------- меню сообщения ---------- */
.msg-menu { background: rgba(30, 36, 50, .94); backdrop-filter: blur(20px); border-radius: 14px; padding: 4px; }
.msg-menu button { padding: 11px 14px; font-size: 15px; border-radius: 10px; }

/* ---------- настройки как в iOS ---------- */
.group-title {
  margin: 18px 4px 6px; font-size: 13px; color: var(--ios-gray); text-transform: uppercase; letter-spacing: .3px;
}
.group { background: var(--ios-cell); border-radius: 12px; overflow: hidden; }
.group + .group { margin-top: 18px; }
.cell { display: flex; align-items: center; min-height: 46px; padding: 10px 16px; position: relative; width: 100%; }
.cell + .cell::before { content: ""; position: absolute; top: 0; left: 16px; right: 0; border-top: 1px solid var(--ios-hair); }
.field-cell { flex-direction: column; align-items: stretch; gap: 4px; font-size: 12px; color: var(--ios-gray); }
.card .field-cell input, .card .field-cell .input-prefix { border: 0; background: transparent; padding-left: 0; padding-right: 0; }
.card .field-cell input:focus { box-shadow: none; }
.card .field-cell .input-prefix span { padding-left: 0; }
.cell-label { font-size: 12px; }
.kv { justify-content: space-between; gap: 12px; font-size: 16px; }
.kv span:last-child { color: var(--ios-gray); text-align: right; overflow: hidden; text-overflow: ellipsis; }
.link-cell { color: var(--ios-blue); text-decoration: none; font-size: 16px; }
.danger-cell { border: 0; background: none; color: #ff453a; font-size: 16px; cursor: pointer; justify-content: center; }
.switch-row { margin: 0; }
#form-profile .btn { margin-top: 14px; }

.profile-top { display: none; }
.me-head { display: none; }
.settings-mode.auth { place-items: start center; background: var(--bg); padding: 0; }
.settings-mode .card { max-width: 600px; background: transparent; border: 0; border-radius: 0; padding: 0 16px 32px; }
.settings-mode .profile-top {
  display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; height: 52px; margin: 0 -8px 6px;
}
.back-link { display: flex; align-items: center; border: 0; background: none; color: var(--ios-blue); font-size: 17px; cursor: pointer; padding: 0; }
.back-link .ico { width: 30px; height: 30px; margin-right: -4px; }
.profile-nav-title { font-size: 17px; font-weight: 700; }
.settings-mode .avatar-edit { flex-direction: column; text-align: center; gap: 8px; margin: 8px 0 4px; }
.settings-mode .avatar.xl { width: 100px; height: 100px; font-size: 36px; }
.settings-mode .me-head { display: block; }
.me-head-name { font-size: 24px; font-weight: 700; }
.me-head-sub { color: var(--ios-gray); font-size: 15px; margin-top: 3px; }
.settings-mode .avatar-actions { flex-direction: row; gap: 18px; }
.settings-mode #profile-title, .settings-mode #profile-hint { display: none; }

/* ---------- телефон ---------- */
@media (max-width: 720px) {
  .back-btn { visibility: visible; }
  .msg { max-width: 82%; }
}
.card input.switch { width: 50px; height: 30px; padding: 0; flex: none; border-radius: 15px; }
.card input.switch::after { width: 26px; height: 26px; top: 1px; left: 1px; }
.card input.switch:checked { background: #34c759; border-color: #34c759; }
.card input.switch:checked::after { transform: translateX(20px); }
.settings-mode .avatar-actions .link { color: var(--ios-blue); }
.settings-mode .avatar-actions .link.danger { color: #ff453a; }
#profile-extra { border-top: 0; margin-top: 6px; padding-top: 0; }
.card label.switch-row { flex-direction: row; align-items: center; gap: 14px; color: var(--text); font-size: 15px; }

/* ================= Этап 1: реакции, закреп, поиск, профиль, эмодзи ================= */
.chat { position: relative; }
button.avatar { border: 0; padding: 0; cursor: pointer; }
.chat-head .peer {
  border: 0; background: none; color: inherit; cursor: pointer; display: flex; flex-direction: column;
  align-items: center; padding: 4px 8px; border-radius: 10px; max-width: 100%;
}
.chat-head .peer-name { display: flex; gap: 4px; align-items: center; max-width: 100%; overflow: hidden; }
.chat-head .peer-name > span:first-child { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.muted-ico { font-size: 12px; opacity: .7; }
.head-right { justify-self: end; display: flex; align-items: center; gap: 4px; }
.head-right .nav-icon-btn { width: 38px; height: 38px; display: grid; place-items: center; }
.head-right .nav-icon-btn .ico { fill: var(--ios-blue); }

/* список чатов */
.badge.muted { background: #4a5263; }
.pin-ico { font-size: 13px; opacity: .65; margin-top: 8px; filter: grayscale(1); }
.item.pinned { background: rgba(255,255,255,.025); }
.item.pinned:hover { background: var(--hover); }

/* закреплённое сообщение */
.pinned-bar {
  display: flex; align-items: center; gap: 10px; padding: 6px 6px 6px 14px; cursor: pointer;
  background: var(--ios-bar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--ios-hair);
}
.pb-line { width: 2px; align-self: stretch; border-radius: 1px; background: var(--ios-blue); }
.pb-body { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.pb-title { color: var(--ios-blue); font-size: 13.5px; font-weight: 600; }
.pb-text { font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pinned-bar .icon-btn { color: var(--ios-gray); display: grid; place-items: center; }
.pinned-bar .icon-btn .ico { width: 18px; height: 18px; fill: currentColor; }

/* поиск по переписке */
.chat-search {
  display: flex; align-items: center; gap: 4px; height: 56px; padding: 0 12px 0 0;
  background: var(--ios-bar); backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  border-bottom: 1px solid var(--ios-hair);
}
.chat-search .cs-field { flex: 1; }
.cs-cancel { color: var(--ios-blue); font-size: 16px; }
.cs-nav {
  display: flex; align-items: center; gap: 4px; padding: 6px 10px calc(6px + env(safe-area-inset-bottom)) 16px;
  background: var(--ios-bar); border-top: 1px solid var(--ios-hair);
}
#cs-count { flex: 1; color: var(--ios-gray); font-size: 15px; }
.cs-nav .icon-btn { display: grid; place-items: center; }
.cs-nav .icon-btn .ico { width: 28px; height: 28px; fill: var(--ios-blue); }
.cs-nav .icon-btn:disabled .ico { fill: #3a4252; }

/* реакции */
.reacts { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.react {
  display: inline-flex; align-items: center; gap: 4px; height: 26px; padding: 0 9px 0 7px; border-radius: 13px;
  border: 0; cursor: pointer; background: rgba(62,136,247,.18); color: var(--ios-blue); font-size: 13px; font-weight: 600;
}
.react .re { font-size: 15px; }
.react.mine { background: var(--ios-blue); color: #fff; }
.msg.out .react { background: rgba(255,255,255,.18); color: #fff; }
.msg.out .react.mine { background: #fff; color: var(--bubble-out); }
.msg.has-img .reacts { margin: 6px 6px 2px; }
.react-row { display: flex; gap: 2px; padding: 4px 4px 6px; border-bottom: 1px solid var(--ios-hair); margin-bottom: 4px; }
.msg-menu .react-row button.rr {
  width: 36px; height: 36px; padding: 0; font-size: 22px; border-radius: 50%; display: grid; place-items: center;
  transition: transform .12s;
}
.msg-menu .react-row button.rr:hover { transform: scale(1.2); background: none; }
.msg-menu .react-row button.rr.mine { background: rgba(62,136,247,.35); }

/* поле ввода и эмодзи */
.input-wrap { flex: 1; position: relative; display: flex; }
.input-wrap textarea { flex: 1; padding-right: 40px; }
.emoji-btn {
  position: absolute; right: 4px; bottom: 3px; width: 30px; height: 30px; border: 0; background: none;
  display: grid; place-items: center; cursor: pointer; border-radius: 50%;
}
.emoji-btn .ico { width: 24px; height: 24px; fill: var(--ios-gray); }
.emoji-btn:hover .ico, .emoji-btn.active .ico { fill: var(--ios-blue); }
.emoji-panel {
  height: 290px; display: flex; flex-direction: column; background: var(--ios-bar);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px); border-top: 1px solid var(--ios-hair);
}
.ep-grid {
  flex: 1; overflow-y: auto; padding: 4px 8px; display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
  align-content: start;
}
.ep-title { grid-column: 1 / -1; color: var(--ios-gray); font-size: 12px; text-transform: uppercase; padding: 6px 4px; letter-spacing: .3px; }
.ep-empty { grid-column: 1 / -1; color: var(--ios-gray); padding: 24px; text-align: center; }
.ep-e { width: 40px; height: 40px; border: 0; background: none; font-size: 27px; cursor: pointer; border-radius: 8px; padding: 0; }
.ep-e:hover { background: rgba(255,255,255,.07); }
.ep-tabs { display: flex; justify-content: space-around; border-top: 1px solid var(--ios-hair); padding: 4px 4px calc(4px + env(safe-area-inset-bottom)); }
.ep-tabs button { border: 0; background: none; font-size: 20px; padding: 4px 6px; border-radius: 8px; cursor: pointer; opacity: .5; filter: grayscale(.6); }
.ep-tabs button.active { opacity: 1; filter: none; background: rgba(255,255,255,.08); }

/* профиль собеседника */
.peer-profile {
  position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; background: var(--bg);
}
.pp-head {
  height: 56px; display: flex; align-items: center; padding: 0 8px; flex: none;
  background: var(--ios-bar); border-bottom: 1px solid var(--ios-hair);
}
.pp-body { flex: 1; overflow-y: auto; padding: 0 16px 32px; width: 100%; max-width: 640px; margin: 0 auto; }
.pp-top { display: flex; flex-direction: column; align-items: center; text-align: center; padding: 20px 0 14px; }
.pp-top .avatar.xl { width: 100px; height: 100px; font-size: 36px; }
.avatar.clickable { cursor: zoom-in; }
.pp-name { font-size: 24px; font-weight: 700; margin-top: 12px; overflow-wrap: anywhere; }
.pp-status { color: var(--ios-gray); font-size: 15px; margin-top: 2px; }
.pp-status.on { color: var(--ios-blue); }
.pp-actions { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; margin-bottom: 18px; }
.pp-action {
  display: flex; flex-direction: column; align-items: center; gap: 4px; padding: 10px 4px 8px; border: 0;
  border-radius: 12px; background: var(--ios-cell); color: var(--ios-blue); font-size: 12px; cursor: pointer;
}
.pp-action:hover { background: #172034; }
.pa-ico { font-size: 20px; }
.info-cell { flex-direction: column; align-items: flex-start; gap: 2px; }
.info-cell.clickable { cursor: pointer; }
.info-cell.clickable:hover { background: #151d2e; }
.ic-label { font-size: 13px; color: var(--ios-gray); }
.ic-value { font-size: 16px; overflow-wrap: anywhere; white-space: pre-wrap; }
.pp-seg { display: flex; background: var(--ios-field); border-radius: 9px; padding: 2px; margin: 22px 0 12px; }
.pp-seg button { flex: 1; border: 0; background: none; color: var(--text); padding: 6px; border-radius: 7px; cursor: pointer; font-size: 14px; }
.pp-seg button.active { background: #2b3446; font-weight: 600; }
.pp-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 2px; border-radius: 10px; overflow: hidden; }
.pp-grid img { width: 100%; aspect-ratio: 1; object-fit: cover; cursor: zoom-in; display: block; background: #111827; }
.pp-files .att-file { color: var(--text); text-decoration: none; gap: 12px; border-radius: 0; margin: 0; }
.pp-files .file-ico { background: var(--ios-blue); color: #fff; }
.pp-files .file-name { max-width: none; }

/* настройки: о себе и день рождения */
.group-hint { margin: 6px 4px 0; color: var(--ios-gray); }
.card .field-cell input[type=date] { color-scheme: dark; }
.reacts .msg-meta { float: none; margin: 0 0 -2px auto; padding-left: 10px; align-self: flex-end; }
