:root {
  --bg: #050507;
  --panel: #111115;
  --card: #1a1a20;
  --card-2: #212128;
  --line: rgba(255, 255, 255, .07);
  --text: #ececf1;
  --muted: #8b8b98;
  --faint: #5d5d69;
  --red: #ff5b6b;
  --green: #3fd27f;
  --accent: #7c6cf0;
  --accent-soft: rgba(124, 108, 240, .18);
  --radius: 28px;
  --vh: 100dvh;
  font-family: "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  color-scheme: dark;
}
body[data-theme="ocean"] { --accent: #3d8bff; --accent-soft: rgba(61, 139, 255, .18); }
body[data-theme="rose"] { --accent: #f2558f; --accent-soft: rgba(242, 85, 143, .18); }
body[data-theme="mint"] { --accent: #22b88d; --accent-soft: rgba(34, 184, 141, .18); }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); overflow: hidden; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }
input { font: inherit; color: inherit; }
svg.i { width: 1em; height: 1em; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }

#stars { position: fixed; inset: 0; pointer-events: none; }
#stars span { position: absolute; width: 3px; height: 3px; border-radius: 50%; background: #8f86ff; box-shadow: 0 0 6px 2px rgba(124, 108, 240, .45); opacity: .5; animation: twinkle 4s ease-in-out infinite; }
@keyframes twinkle { 50% { opacity: .1; } }
body.calm #stars span { animation: none; }
body.calm * { transition: none !important; animation-duration: 0s !important; }

.shell { position: relative; height: var(--vh); display: flex; justify-content: center; gap: 20px; padding: 20px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.side { width: 360px; flex: none; }
.main { width: 730px; max-width: calc(100vw - 420px); position: relative; }

@media (max-width: 899px) {
  .shell { padding: 0; }
  .panel { border-radius: 0; border: 0; }
  .side { width: 100%; }
  .main { position: fixed; inset: 0; max-width: none; width: 100%; transform: translateX(100%); transition: transform .25s ease; z-index: 5; }
  .shell.open .main { transform: none; }
}

/* Шапка с вкладками */
.side-head { display: flex; gap: 8px; align-items: center; padding: 20px 20px 10px; }
.seg { flex: 1; display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 4px; }
.seg button { flex: 1; padding: 8px 4px; border-radius: 18px; font-size: 14px; color: var(--muted); transition: background .2s, color .2s; white-space: nowrap; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 700; }
.round-btn { width: 44px; height: 44px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 19px; flex: none; }
.search-row { padding: 0 20px 8px; }
.search-row input { width: 100%; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px 14px; outline: none; }
.side-body { flex: 1; overflow-y: auto; padding: 0 8px 24px; overscroll-behavior: contain; }
.side-body::-webkit-scrollbar, .scroll::-webkit-scrollbar { width: 0; }

.caps { display: flex; justify-content: space-between; align-items: baseline; padding: 10px 12px 8px; font-size: 13px; letter-spacing: .02em; text-transform: uppercase; color: var(--muted); }
.caps small { text-transform: none; font-size: 11px; }

/* Аватарки */
.ava { position: relative; border-radius: 50%; flex: none; display: grid; place-items: center; font-weight: 800; color: #fff; overflow: hidden; background: linear-gradient(135deg, #6b5cf0, #b25ce0); }
.ava img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ava.s56 { width: 56px; height: 56px; font-size: 20px; }
.ava.s44 { width: 44px; height: 44px; font-size: 16px; }
.ava.s32 { width: 30px; height: 30px; font-size: 12px; }
.ava.s92 { width: 92px; height: 92px; font-size: 34px; }

.stories { display: flex; gap: 16px; overflow-x: auto; padding: 4px 12px 14px; }
.stories::-webkit-scrollbar { display: none; }
.story { width: 62px; flex: none; text-align: center; font-size: 11px; color: var(--muted); }
.story .ring { position: relative; width: 62px; height: 62px; border-radius: 50%; padding: 3px; background: linear-gradient(135deg, var(--accent), #b25ce0); }
.story .ring .ava { width: 56px; height: 56px; border: 2px solid var(--panel); }
.story .badge { position: absolute; right: -2px; bottom: 0; }
.story div.n { margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--red); color: #fff; font-size: 11px; font-weight: 800; display: inline-grid; place-items: center; border: 2px solid var(--panel); }

/* Список чатов */
.chat-row { display: flex; gap: 12px; align-items: center; width: 100%; text-align: left; padding: 9px 12px; border-radius: 18px; transition: background .15s; }
.chat-row:hover, .chat-row.on { background: var(--card); }
.chat-row .body { flex: 1; min-width: 0; padding: 6px 0; border-bottom: 1px solid var(--line); }
.chat-row.on .body, .chat-row:hover .body { border-color: transparent; }
.line { display: flex; gap: 8px; align-items: center; justify-content: space-between; }
.line .name { font-weight: 700; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.line .time { font-size: 12px; color: var(--muted); flex: none; }
.preview { font-size: 14px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: flex; gap: 4px; align-items: center; min-width: 0; }
.preview .you { color: var(--accent); flex: none; }
.preview .txt { overflow: hidden; text-overflow: ellipsis; }
.del-pill { flex: none; display: inline-flex; gap: 3px; align-items: center; font-size: 12px; font-weight: 700; color: var(--red); background: rgba(255, 91, 107, .14); padding: 2px 7px; border-radius: 9px; }
.blur { filter: blur(5px); transition: filter .2s; }
.blur.show { filter: none; }

/* Пустые состояния */
.empty { padding: 60px 28px; text-align: center; color: var(--muted); line-height: 1.6; font-size: 15px; }
.center-state { height: 100%; display: grid; place-content: center; justify-items: center; gap: 18px; color: var(--muted); text-align: center; padding: 24px; }
.center-state .logo { width: 80px; height: 80px; border-radius: 24px; background: var(--accent); display: grid; place-items: center; color: #fff; font-size: 38px; }

/* Удалённые */
.subseg { margin: 4px 12px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 4px; display: grid; grid-template-columns: 1fr 1fr; gap: 2px; }
.subseg button { padding: 8px; border-radius: 14px; font-size: 13px; color: var(--muted); }
.subseg button.wide { grid-column: 1 / -1; display: flex; gap: 6px; justify-content: center; align-items: center; }
.subseg button.on { background: var(--card-2); color: var(--text); font-weight: 700; }
.chips { display: flex; gap: 6px; padding: 0 12px 10px; }
.chips button { padding: 6px 11px; border-radius: 14px; background: var(--card); font-size: 12px; color: var(--muted); }
.chips button.on { background: var(--card-2); color: var(--text); font-weight: 700; }
.del-card { margin: 0 4px 10px; background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 14px; display: block; width: calc(100% - 8px); text-align: left; }
.del-card .head { display: flex; gap: 10px; align-items: center; }
.del-card .who { flex: 1; min-width: 0; }
.del-card .sub { color: var(--red); font-size: 12px; display: flex; gap: 4px; align-items: center; margin-top: 2px; }
.del-card .lines { margin: 12px 0 8px 4px; border-left: 2px solid var(--red); padding-left: 12px; display: grid; gap: 4px; font-size: 14px; }
.del-card .lines .you { color: var(--accent); }
.del-card .lines img { max-width: 100%; max-height: 160px; border-radius: 12px; display: block; margin-top: 4px; }
.del-card .foot { font-size: 11px; color: var(--faint); }
.more { display: block; margin: 6px auto 16px; padding: 9px 18px; border-radius: 16px; background: var(--card); color: var(--muted); font-size: 13px; }

/* Профиль */
.me { text-align: center; padding: 14px 0 6px; }
.me .ava { margin: 0 auto 12px; }
.me h2 { margin: 0; font-size: 24px; }
.me .un { color: var(--muted); font-size: 14px; margin-top: 4px; }
.stats { margin: 16px 12px; display: grid; grid-template-columns: repeat(3, 1fr); background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 14px 4px; }
.stats div { text-align: center; border-left: 1px solid var(--line); }
.stats div:first-child { border: 0; }
.stats b { display: block; font-size: 20px; }
.stats b.acc { color: var(--accent); }
.stats span { font-size: 11px; color: var(--muted); }
.group { margin: 0 12px; background: var(--card); border: 1px solid var(--line); border-radius: 22px; overflow: hidden; }
.group-title { padding: 18px 28px 8px; font-size: 13px; text-transform: uppercase; color: var(--muted); letter-spacing: .02em; }
.note { padding: 8px 28px 0; font-size: 12px; color: var(--faint); line-height: 1.5; }
.row { display: flex; gap: 12px; align-items: center; width: 100%; padding: 12px 16px; text-align: left; position: relative; }
.row + .row::before { content: ""; position: absolute; top: 0; left: 58px; right: 16px; border-top: 1px solid var(--line); }
.row .ic { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-size: 16px; flex: none; }
.row .t { flex: 1; min-width: 0; }
.row .t div { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .t small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; white-space: normal; }
.row .v { color: var(--muted); font-size: 15px; flex: none; display: flex; gap: 6px; align-items: center; }
.row .v.ok { color: var(--green); }
.row .chev { color: var(--faint); }
.row.danger .t { color: var(--red); }
.sw { width: 52px; height: 30px; border-radius: 15px; background: #3a3a44; position: relative; flex: none; transition: background .2s; }
.sw::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.sw.on { background: var(--accent); }
.sw.on::after { transform: translateX(22px); }
.brand { text-align: center; padding: 28px 0 10px; color: var(--muted); }
.brand b { display: block; font-size: 18px; color: var(--text); }
.brand small { font-size: 12px; }
.c-blue { background: #3d8bff; } .c-violet { background: #8b6cf0; } .c-green { background: #34c46e; } .c-orange { background: #f59a23; }
.c-red { background: #f2556a; } .c-pink { background: #e8559b; } .c-gray { background: #5d5d6b; } .c-teal { background: #1fb5a8; }

/* Окно чата */
.main-body { flex: 1; min-height: 0; display: flex; flex-direction: column; position: relative; }
.topbar { position: absolute; top: 0; left: 0; right: 0; z-index: 3; display: flex; align-items: center; justify-content: center; padding: 10px 12px 26px; background: linear-gradient(var(--panel) 40%, transparent); pointer-events: none; }
.topbar > * { pointer-events: auto; }
.back { position: absolute; left: 12px; top: 12px; width: 40px; height: 40px; border-radius: 50%; background: var(--card); border: 1px solid var(--line); display: grid; place-items: center; font-size: 18px; }
.pill { display: flex; gap: 8px; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 4px 16px 4px 4px; max-width: 70%; text-align: left; }
.pill b { display: block; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill small { display: block; font-size: 11px; color: var(--muted); white-space: nowrap; }
.scroll { flex: 1; overflow-y: auto; overscroll-behavior: contain; padding: 72px 14px 14px; }
.msgs { display: flex; flex-direction: column; gap: 4px; }
.day-sep { align-self: center; margin: 12px 0 6px; padding: 3px 12px; border-radius: 12px; background: rgba(30, 30, 38, .9); font-size: 12px; color: var(--muted); position: sticky; top: 64px; z-index: 1; }
.msg { max-width: min(78%, 520px); padding: 8px 12px 6px; border-radius: 20px; background: var(--card-2); align-self: flex-start; font-size: 15px; line-height: 1.38; word-wrap: break-word; overflow-wrap: anywhere; position: relative; }
.msg.out { align-self: flex-end; background: var(--accent); color: #fff; }
.msg.deleted { box-shadow: inset 0 0 0 1.5px var(--red); }
.msg.deleted.out { background: color-mix(in srgb, var(--accent) 55%, #3a1520); }
.msg .meta { display: flex; gap: 6px; justify-content: flex-end; align-items: center; font-size: 11px; opacity: .7; margin-top: 2px; }
.msg .meta .gone { color: #ffd0d5; opacity: 1; display: inline-flex; gap: 3px; align-items: center; }
.msg.in .meta .gone { color: var(--red); }
.msg .meta .edited { text-decoration: underline dotted; cursor: pointer; }
.msg .quote { border-left: 3px solid currentColor; padding: 2px 8px; margin-bottom: 4px; font-size: 13px; opacity: .8; border-radius: 4px; background: rgba(0, 0, 0, .12); max-height: 3.2em; overflow: hidden; }
.msg.media-only { padding: 4px; }
.msg.media-only .meta { padding: 0 8px 2px; }
.msg img.ph, .msg video.vid { display: block; max-width: 100%; max-height: 360px; border-radius: 16px; background: rgba(0, 0, 0, .2); cursor: zoom-in; min-width: 120px; min-height: 80px; object-fit: cover; }
.msg video.round { width: 220px; height: 220px; border-radius: 50%; object-fit: cover; display: block; }
.msg.sticker { background: none; box-shadow: none; padding: 0; }
.msg.sticker img, .msg.sticker video { width: 160px; height: 160px; object-fit: contain; display: block; }
.msg .big-emoji { font-size: 64px; line-height: 1.1; }
.msg audio { width: 260px; max-width: 100%; display: block; height: 40px; }
.msg .file { display: flex; gap: 10px; align-items: center; color: inherit; text-decoration: none; }
.msg .file .ic { width: 40px; height: 40px; border-radius: 50%; background: rgba(255, 255, 255, .15); display: grid; place-items: center; font-size: 18px; flex: none; }
.msg .file small { display: block; opacity: .7; font-size: 12px; }
.msg .label { opacity: .8; font-style: italic; }
.msg a { color: inherit; }
.loader { text-align: center; color: var(--muted); padding: 10px; font-size: 13px; }
.composer { display: flex; gap: 8px; align-items: center; padding: 10px 14px 14px; }
.composer .field { flex: 1; background: var(--card); border: 1px solid var(--line); border-radius: 22px; padding: 11px 16px; color: var(--faint); font-size: 14px; }

/* Аналитика */
.an { padding: 72px 14px 30px; }
.an .hero { text-align: center; padding: 8px 0 10px; }
.an .hero .ava { margin: 0 auto 10px; }
.an .hero h2 { margin: 0; font-size: 24px; }
.an .hero small { color: var(--muted); }
.an .group { margin: 0; }
.an .group-title { padding: 22px 16px 8px; }
.an .note { padding: 8px 16px 0; }
.bars { padding: 4px 16px; }
.bar-block { padding: 12px 0; border-bottom: 1px solid var(--line); }
.bar-block:last-child { border: 0; }
.bar-block .title { font-size: 15px; margin-bottom: 10px; }
.split { display: flex; gap: 4px; height: 6px; }
.split i { display: block; border-radius: 3px; background: #3a3a44; }
.split i:first-child { background: var(--accent); }
.split-legend { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 8px; }
.split-legend span:first-child { color: var(--accent); }
.hours { display: flex; align-items: flex-end; gap: 3px; height: 90px; padding: 16px 16px 0; }
.hours i { flex: 1; border-radius: 8px; background: #3a3a44; min-height: 6px; }
.hours i.peak { background: var(--accent); }
.hours-axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); padding: 6px 16px 0; }
.chart-cap { font-size: 12px; color: var(--muted); padding: 10px 16px 14px; border-bottom: 1px solid var(--line); }
.spark { padding: 16px; }
.spark svg { width: 100%; height: 70px; display: block; }
.spark .axis { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 6px; }
.words { display: grid; grid-template-columns: 1fr 1fr; gap: 0 24px; padding: 10px 16px; }
.words div { display: flex; justify-content: space-between; padding: 6px 0; font-size: 15px; }
.words span { color: var(--muted); font-size: 13px; }
.soon { padding: 16px; color: var(--muted); font-size: 14px; line-height: 1.5; }

/* Всплывающая панель */
.sheet-wrap { position: fixed; inset: 0; z-index: 20; display: grid; align-items: end; justify-items: center; }
.sheet-bg { position: absolute; inset: 0; background: rgba(0, 0, 0, .55); }
.sheet { position: relative; width: min(520px, 100%); max-height: 85dvh; overflow-y: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 28px 28px 0 0; padding: 22px 18px calc(24px + env(safe-area-inset-bottom)); animation: up .22s ease; }
@media (min-width: 900px) { .sheet-wrap { align-items: center; } .sheet { border-radius: 28px; } }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet h3 { margin: 0 0 6px; font-size: 20px; }
.sheet p { color: var(--muted); margin: 0 0 14px; line-height: 1.5; font-size: 14px; }
.sheet .group { margin: 0 0 14px; }
.btn { width: 100%; padding: 14px; border-radius: 18px; background: var(--accent); color: #fff; font-weight: 800; font-size: 16px; }
.btn.ghost { background: var(--card); color: var(--text); margin-top: 8px; }
.btn.red { background: var(--red); }
.btn:disabled { opacity: .5; }
.theme-dot { width: 14px; height: 14px; border-radius: 50%; display: inline-block; }
.history { display: grid; gap: 8px; margin-bottom: 14px; }
.history div { background: var(--card); border-radius: 14px; padding: 10px 12px; font-size: 14px; }
.history small { display: block; color: var(--muted); font-size: 11px; margin-bottom: 4px; }

.viewer { position: fixed; inset: 0; z-index: 30; background: rgba(0, 0, 0, .92); display: grid; place-items: center; }
.viewer img, .viewer video { max-width: 96vw; max-height: 90dvh; border-radius: 12px; }
.toast { position: fixed; left: 50%; bottom: 28px; transform: translateX(-50%); z-index: 40; background: var(--card-2); border: 1px solid var(--line); padding: 10px 18px; border-radius: 16px; font-size: 14px; max-width: 90vw; }
