:root {
    --primary: #2c3e50; --primary-2: #34495e;
    --accent: #27ae60; --accent-2: #219a52;
    --blue: #3498db; --red: #e74c3c; --orange: #f39c12; --purple: #9b59b6;
    --bg: #eef1f4; --card: #fff; --text: #2c3e50; --muted: #7f8c8d;
    --radius: 14px; --nav-h: 64px;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; }
body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
    background: var(--bg); color: var(--text); font-size: 15px;
    -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
.muted { color: var(--muted); font-size: 14px; }

.appbar {
    position: sticky; top: 0; z-index: 50;
    background: var(--primary); color: #fff;
    padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,.15);
}
.appbar h1 { font-size: 18px; margin: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.appbar .sub { font-size: 12px; opacity: .75; margin-top: 2px; }
.appbar .title { flex: 1; min-width: 0; }
.icon-btn {
    width: 40px; height: 40px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 20px; background: rgba(255,255,255,.12); color: #fff;
    border: none; cursor: pointer; position: relative;
}
.icon-btn.bell .badge-dot {
    position: absolute; top: -3px; right: -3px;
    background: var(--red); color: #fff; font-size: 10px;
    min-width: 18px; height: 18px; border-radius: 9px;
    display: flex; align-items: center; justify-content: center;
    font-weight: 700; padding: 0 4px; border: 2px solid var(--primary);
    box-sizing: content-box;
}

.page {
    max-width: 900px; margin: 0 auto;
    padding: 16px 16px calc(var(--nav-h) + env(safe-area-inset-bottom) + 90px);
}

.search {
    display: flex; align-items: center; gap: 8px; background: #fff;
    border-radius: 12px; padding: 4px 4px 4px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.search input { flex: 1; min-width: 0; border: none; outline: none; font-size: 16px; padding: 10px 0; background: transparent; }
.search button { border: none; background: var(--blue); color: #fff; border-radius: 10px; padding: 10px 14px; font-size: 15px; font-weight: 600; cursor: pointer; }

.chips { display: flex; gap: 8px; overflow-x: auto; padding: 14px 0 6px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip {
    padding: 8px 16px; border-radius: 20px; background: #fff; color: var(--primary-2);
    font-weight: 600; font-size: 14px; white-space: nowrap; box-shadow: 0 1px 2px rgba(0,0,0,.06);
}
.chip.active { background: var(--primary); color: #fff; }
.count { font-size: 13px; color: var(--muted); margin: 8px 2px 10px; }

.list { display: grid; gap: 10px; }
@media (min-width: 700px) { .list { grid-template-columns: 1fr 1fr; } }
.s-card {
    background: var(--card); border-radius: var(--radius); padding: 14px;
    display: flex; align-items: center; gap: 12px;
    box-shadow: 0 1px 3px rgba(0,0,0,.08); transition: transform .1s;
}
.s-card:active { transform: scale(.98); }
.s-info { flex: 1; min-width: 0; }
.s-name { font-weight: 700; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.s-meta { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chev { color: #bdc3c7; font-size: 26px; line-height: 1; }

.avatar {
    width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
    background: var(--accent); color: #fff; font-weight: 700; font-size: 18px;
    display: flex; align-items: center; justify-content: center;
}
.avatar.dead { background: var(--red); }
.avatar.missing { background: var(--orange); }
.avatar.leave { background: var(--blue); }
.avatar.soch { background: var(--purple); }

.badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 12px; font-weight: 700; margin-top: 6px; }
.badge.dead { background: #fdecea; color: var(--red); }
.badge.missing { background: #fef5e7; color: #d68910; }
.badge.leave { background: #ebf5fb; color: var(--blue); }
.badge.soch { background: #f4ecf7; color: var(--purple); }
.badge.living { background: #e9f7ef; color: var(--accent); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 8px; background: #ecf0f1; font-size: 12px; font-weight: 600; color: var(--primary-2); margin-left: 4px; }

.empty { text-align: center; color: var(--muted); padding: 40px 10px; }

.fab {
    position: fixed; right: 18px; z-index: 60;
    bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 18px);
    width: 58px; height: 58px; border-radius: 50%; border: none; cursor: pointer;
    background: var(--accent); color: #fff; font-size: 32px; line-height: 1;
    box-shadow: 0 4px 14px rgba(39,174,96,.45);
}

.bottom-nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 70;
    height: calc(var(--nav-h) + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
    background: #fff; display: flex; border-top: 1px solid #e1e5ea;
    box-shadow: 0 -2px 10px rgba(0,0,0,.05);
}
.bottom-nav a {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 3px; font-size: 11px; color: var(--muted); font-weight: 600;
}
.bottom-nav a .ico { font-size: 22px; line-height: 1; }
.bottom-nav a.active { color: var(--accent); }

.card { background: #fff; border-radius: var(--radius); padding: 16px; margin-bottom: 14px; box-shadow: 0 1px 3px rgba(0,0,0,.08); }
.card h3 { margin: 0 0 12px; font-size: 16px; }
.hero { display: flex; align-items: center; gap: 14px; }
.hero .avatar { width: 62px; height: 62px; font-size: 26px; }
.hero .s-name { white-space: normal; font-size: 18px; }
.row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px solid #f0f2f4; }
.row:last-child { border-bottom: none; }
.row .l { color: var(--muted); font-size: 14px; }
.row .v { font-weight: 600; text-align: right; word-break: break-word; }

.note { border-left: 4px solid; }
.note.blue { background: #e8f4f8; border-color: var(--blue); }
.note.yellow { background: #fef9e7; border-color: #f1c40f; }
.note.red { background: #fdf2f2; border-color: var(--red); }
.pre { white-space: pre-wrap; word-wrap: break-word; font-size: 14px; line-height: 1.5; }

details > summary { cursor: pointer; list-style: none; }
details > summary::-webkit-details-marker { display: none; }
.spoiler summary { color: var(--muted); font-size: 14px; padding: 4px 0; }

.item { display: flex; gap: 12px; align-items: flex-start; padding: 12px 0; border-bottom: 1px solid #f0f2f4; }
.item:last-of-type { border-bottom: none; }
.item .grow { flex: 1; min-width: 0; }
.item small { display: block; color: var(--muted); margin-top: 4px; word-break: break-word; }
.item a.tel { display: block; color: var(--blue); font-weight: 600; margin-top: 4px; }
.thumb { width: 52px; height: 52px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }
.file-ico { width: 52px; height: 52px; border-radius: 8px; background: #ecf0f1; display: flex; align-items: center; justify-content: center; font-size: 24px; flex-shrink: 0; }
.fname { font-weight: 600; word-break: break-all; }
.actions { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 6px;
    border: none; border-radius: 10px; padding: 10px 14px; cursor: pointer;
    font-size: 14px; font-weight: 700; color: #fff; background: var(--blue); font-family: inherit;
}
.btn.green { background: var(--accent); }
.btn.red { background: var(--red); }
.btn.gray { background: #ecf0f1; color: var(--text); }
.btn.sm { padding: 6px 12px; font-size: 13px; }
.btn.block { width: 100%; padding: 14px; font-size: 16px; }

.field { margin-bottom: 12px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
.input {
    width: 100%; padding: 12px; border: 1px solid #dfe4ea; border-radius: 10px;
    font-size: 16px; background: #fafbfc; outline: none; font-family: inherit; color: var(--text);
}
.input:focus { border-color: var(--blue); background: #fff; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 12px; }
@media (min-width: 600px) { .grid2 { grid-template-columns: 1fr 1fr; } }
.add-box { margin-top: 12px; }
.add-box form { margin-top: 12px; }

.file-pick {
    position: relative; display: flex; align-items: center; justify-content: center;
    padding: 14px; border: 2px dashed #cfd6dd; border-radius: 10px; color: var(--muted);
    font-weight: 600; margin: 12px 0 10px; text-align: center; word-break: break-all;
}
.file-pick input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }

.sheet-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 100; display: none; align-items: flex-end; justify-content: center; }
.sheet-overlay.open { display: flex; }
.sheet {
    background: #fff; width: 100%; max-width: 560px; max-height: 90vh; overflow-y: auto;
    border-radius: 20px 20px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
    animation: sheetUp .25s ease-out;
}
.sheet .grab { width: 40px; height: 5px; background: #dfe4ea; border-radius: 3px; margin: 4px auto 14px; }
.sheet h3 { margin: 0 0 16px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet-actions .btn { flex: 1; padding: 14px; font-size: 15px; }
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: none; } }
@media (min-width: 700px) { .sheet-overlay { align-items: center; } .sheet { border-radius: 20px; } }

.login-wrap {
    min-height: 100vh; min-height: 100dvh; padding: 20px;
    display: flex; align-items: center; justify-content: center;
    background: linear-gradient(160deg, #2c3e50, #1a252f);
}
.login-card { background: #fff; width: 100%; max-width: 360px; border-radius: 20px; padding: 30px 24px; text-align: center; box-shadow: 0 10px 40px rgba(0,0,0,.3); }
.login-card img { width: 84px; height: 84px; border-radius: 22px; margin-bottom: 8px; }
.login-card h2 { margin: 6px 0 4px; }
.login-card form { margin-top: 20px; }
.error { background: #fdecea; color: var(--red); padding: 10px; border-radius: 10px; margin-top: 14px; font-size: 14px; }

.chat-page { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
.chat-box { flex: 1; overflow-y: auto; padding: 14px; background: #e5ddd5; display: flex; flex-direction: column; gap: 8px; }
.msg {
    max-width: 78%; padding: 8px 12px 20px; border-radius: 12px; position: relative;
    font-size: 15px; line-height: 1.35; word-wrap: break-word; box-shadow: 0 1px 1px rgba(0,0,0,.08);
}
.msg .time { font-size: 10px; color: #8a8a8a; position: absolute; bottom: 4px; right: 8px; }
.msg.own { align-self: flex-end; background: #dcf8c6; border-bottom-right-radius: 4px; }
.msg.other { align-self: flex-start; background: #fff; border-bottom-left-radius: 4px; }
.msg .sender { font-size: 12px; font-weight: 700; color: var(--blue); display: block; margin-bottom: 2px; }
.chat-input { display: flex; gap: 8px; padding: 10px 10px calc(10px + env(safe-area-inset-bottom)); background: #f0f0f0; border-top: 1px solid #ddd; }
.chat-input input { flex: 1; min-width: 0; padding: 12px 16px; border: 1px solid #ccc; border-radius: 24px; font-size: 16px; outline: none; }
.chat-input button { width: 48px; height: 48px; border-radius: 50%; border: none; background: var(--accent); color: #fff; font-size: 20px; cursor: pointer; flex-shrink: 0; }

/* ===== Уведомления ===== */
.notif-item {
    display: flex; gap: 12px; padding: 14px; background: #fff;
    border-radius: 12px; margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.08);
}
.notif-item.unread { background: #eaf4fd; border-left: 4px solid var(--blue); }
.notif-item .ico-circle {
    width: 42px; height: 42px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    background: #ecf0f1; font-size: 20px;
}
.notif-item .body { flex: 1; min-width: 0; }
.notif-item .who { font-weight: 700; font-size: 14px; color: var(--primary); }
.notif-item .what { font-size: 14px; color: var(--text); margin-top: 2px; word-wrap: break-word; }
.notif-item .when { font-size: 12px; color: var(--muted); margin-top: 6px; }

/* ===== Смена пароля ===== */
.pw-hint { font-size: 13px; color: var(--muted); text-align: left; margin-top: 6px; line-height: 1.5; }

/* ===== Всплывашки (toasts) ===== */
.toast-container {
    position: fixed;
    top: calc(env(safe-area-inset-top) + 66px);
    right: 12px; left: 12px;
    z-index: 9999;
    display: flex; flex-direction: column; gap: 8px;
    pointer-events: none;
}
@media (min-width: 600px) {
    .toast-container { left: auto; width: 380px; }
}
.toast {
    background: #2c3e50; color: #fff;
    padding: 14px 16px; border-radius: 12px;
    box-shadow: 0 8px 24px rgba(0,0,0,.3);
    animation: toastIn .3s ease-out;
    pointer-events: auto;
    border-left: 4px solid #27ae60;
}
.toast.hide { animation: toastOut .3s ease-in forwards; }
.toast-title { font-weight: 700; font-size: 14px; margin-bottom: 2px; }
.toast-body  { font-size: 13px; opacity: .9; line-height: 1.35; }
@keyframes toastIn  { from { transform: translateY(-20px); opacity: 0; } to { transform: none; opacity: 1; } }
@keyframes toastOut { to   { transform: translateY(-20px); opacity: 0; } }

/* ===== Вложения в чате ===== */
.chat-img {
    max-width: 100%;
    max-height: 320px;
    border-radius: 8px;
    display: block;
    margin-bottom: 6px;
    cursor: pointer;
    background: #f0f0f0;
}
.chat-file {
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(0,0,0,.06);
    padding: 10px 12px;
    border-radius: 8px;
    margin-bottom: 6px;
    color: inherit;
    text-decoration: none;
    max-width: 100%;
}
.chat-file:active { background: rgba(0,0,0,.12); }
.chat-file-ico { font-size: 24px; flex-shrink: 0; }
.chat-file-name {
    font-size: 13px;
    word-break: break-all;
    line-height: 1.3;
}
.attach-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: #fff;
    border: 1px solid #ccc;
    cursor: pointer;
    font-size: 20px;
    flex-shrink: 0;
    user-select: none;
}
.attach-btn:active { background: #e8e8e8; }

/* ===== Список чатов ===== */
.chats-section { margin-bottom: 20px; }
.chats-label {
    font-size: 12px; font-weight: 700; color: var(--muted);
    text-transform: uppercase; letter-spacing: .5px;
    padding: 6px 4px 8px;
}
.chat-row {
    display: flex; align-items: center; gap: 12px;
    background: #fff; border-radius: 12px; padding: 12px 14px;
    margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.06);
    transition: transform .1s;
}
.chat-row:active { transform: scale(.98); }
.chat-avatar {
    width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0;
    display: flex; align-items: center; justify-content: center;
    color: #fff; font-weight: 700; font-size: 18px;
}
.chat-info { flex: 1; min-width: 0; }
.chat-name { font-weight: 700; font-size: 15px; }
.chat-preview {
    font-size: 13px; color: var(--muted); margin-top: 2px;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }

/* ===== Обёртка сообщения с реакциями ===== */
.msg-wrap {
    display: flex; flex-direction: column; gap: 2px;
    max-width: 82%;
}
.msg-wrap.mine { align-self: flex-end; align-items: flex-end; }
.msg-wrap.theirs { align-self: flex-start; align-items: flex-start; }

.msg { position: relative; padding-right: 30px; }
.msg.deleted { opacity: .65; font-style: italic; }
.deleted-text { color: #95a5a6; font-size: 13px; }

.msg-menu-btn {
    position: absolute; top: 4px; right: 4px;
    background: transparent; border: none; cursor: pointer;
    color: #95a5a6; font-size: 16px; padding: 2px 6px;
    border-radius: 50%; opacity: .5; transition: opacity .2s;
}
.msg-menu-btn:hover, .msg-menu-btn:active { opacity: 1; background: rgba(0,0,0,.06); }

/* ===== Реакции ===== */
.reactions {
    display: flex; flex-wrap: wrap; gap: 4px;
    margin-top: 2px; padding: 0 4px;
}
.reaction-chip {
    display: inline-flex; align-items: center; gap: 3px;
    background: #fff; border: 1px solid #dfe4ea;
    border-radius: 14px; padding: 3px 8px;
    font-size: 13px; cursor: pointer; font-family: inherit;
    transition: transform .1s;
}
.reaction-chip:active { transform: scale(.92); }
.reaction-chip.mine { background: #e8f4fd; border-color: var(--blue); }
.rcount { font-size: 11px; color: var(--muted); }
.reaction-add {
    background: transparent; border: 1px dashed #cfd6dd;
    border-radius: 14px; padding: 3px 8px;
    font-size: 12px; cursor: pointer; color: var(--muted);
    font-family: inherit;
}

/* ===== Попапы снизу ===== */
.popup-overlay {
    position: fixed; inset: 0; background: rgba(0,0,0,.45);
    z-index: 200; display: none; align-items: flex-end; justify-content: center;
}
.popup-overlay.open { display: flex; }
.popup-sheet {
    background: #fff; width: 100%; max-width: 500px;
    border-radius: 20px 20px 0 0;
    padding: 10px 18px calc(18px + env(safe-area-inset-bottom));
    animation: sheetUp .25s ease-out;
}
.popup-sheet .grab { width: 40px; height: 5px; background: #dfe4ea; border-radius: 3px; margin: 4px auto 14px; }
.popup-sheet h4 { margin: 0 0 12px; font-size: 16px; }
.popup-item {
    display: flex; align-items: center; gap: 10px;
    width: 100%; padding: 14px 12px; border: none; background: #f8f9fa;
    border-radius: 10px; margin-bottom: 8px; cursor: pointer;
    font-size: 15px; font-family: inherit; text-align: left;
}
.popup-item:active { background: #ecf0f1; }

/* ===== Палитра эмодзи ===== */
.emoji-picker {
    display: grid; grid-template-columns: repeat(5, 1fr);
    gap: 8px; margin-bottom: 14px;
}
.emoji-picker button {
    font-size: 28px; background: #f8f9fa; border: none;
    border-radius: 12px; padding: 12px 0; cursor: pointer;
    transition: transform .1s;
}
.emoji-picker button:active { transform: scale(.9); background: #ecf0f1; }

/* ===== Список чатов ===== */
.chats-section { margin-bottom: 20px; }
.chats-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; padding: 6px 4px 8px; }
.chat-row { display: flex; align-items: center; gap: 12px; background: #fff; border-radius: 12px; padding: 12px 14px; margin-bottom: 8px; box-shadow: 0 1px 3px rgba(0,0,0,.06); transition: transform .1s; }
.chat-row:active { transform: scale(.98); }
.chat-avatar { width: 48px; height: 48px; border-radius: 50%; flex-shrink: 0; display: flex; align-items: center; justify-content: center; color: #fff; font-weight: 700; font-size: 18px; }
.chat-info { flex: 1; min-width: 0; }
.chat-name { font-weight: 700; font-size: 15px; }
.chat-preview { font-size: 13px; color: var(--muted); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.chat-time { font-size: 11px; color: var(--muted); }
.unread-badge {
    background: #e74c3c; color: #fff; font-size: 11px; font-weight: 700;
    min-width: 20px; height: 20px; border-radius: 10px;
    display: flex; align-items: center; justify-content: center;
    padding: 0 6px;
}

/* ===== Обёртка сообщения ===== */
.msg-wrap { display: flex; flex-direction: column; gap: 2px; max-width: 82%; }
.msg-wrap.mine { align-self: flex-end; align-items: flex-end; }
.msg-wrap.theirs { align-self: flex-start; align-items: flex-start; }
.msg { position: relative; padding-right: 30px; }
.msg.deleted { opacity: .65; font-style: italic; }
.deleted-text { color: #95a5a6; font-size: 13px; }
.msg-menu-btn { position: absolute; top: 4px; right: 4px; background: transparent; border: none; cursor: pointer; color: #95a5a6; font-size: 16px; padding: 2px 6px; border-radius: 50%; opacity: .5; transition: opacity .2s; }
.msg-menu-btn:hover, .msg-menu-btn:active { opacity: 1; background: rgba(0,0,0,.06); }

/* ===== Цитата (ответ) ===== */
.reply-quote {
    background: rgba(0,0,0,.06);
    border-left: 3px solid var(--blue);
    padding: 6px 10px;
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    max-width: 100%;
}
.reply-author { font-size: 12px; font-weight: 700; color: var(--blue); margin-bottom: 2px; }
.reply-text { font-size: 12px; color: #555; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* ===== Пересылка ===== */
.forwarded-label {
    font-size: 12px; color: #8e44ad; font-style: italic;
    margin-bottom: 4px; padding: 2px 0;
}

/* ===== Плашка ответа над полем ввода ===== */
.reply-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 8px 12px; background: #eef2f5;
    border-top: 1px solid #dfe4ea;
}
.reply-bar-content { flex: 1; min-width: 0; border-left: 3px solid var(--blue); padding-left: 8px; }
.reply-bar-close { background: transparent; border: none; font-size: 18px; cursor: pointer; color: var(--muted); padding: 4px 8px; }

/* ===== Реакции ===== */
.reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; padding: 0 4px; }
.reaction-chip { display: inline-flex; align-items: center; gap: 3px; background: #fff; border: 1px solid #dfe4ea; border-radius: 14px; padding: 3px 8px; font-size: 13px; cursor: pointer; font-family: inherit; transition: transform .1s; }
.reaction-chip:active { transform: scale(.92); }
.reaction-chip.mine { background: #e8f4fd; border-color: var(--blue); }
.rcount { font-size: 11px; color: var(--muted); }
.reaction-add { background: transparent; border: 1px dashed #cfd6dd; border-radius: 14px; padding: 3px 8px; font-size: 12px; cursor: pointer; color: var(--muted); font-family: inherit; }

/* ===== Попапы ===== */
.popup-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200; display: none; align-items: flex-end; justify-content: center; }
.popup-overlay.open { display: flex; }
.popup-sheet { background: #fff; width: 100%; max-width: 500px; max-height: 85vh; overflow-y: auto; border-radius: 20px 20px 0 0; padding: 10px 18px calc(18px + env(safe-area-inset-bottom)); animation: sheetUp .25s ease-out; }
.popup-sheet .grab { width: 40px; height: 5px; background: #dfe4ea; border-radius: 3px; margin: 4px auto 14px; }
.popup-sheet h4 { margin: 0 0 12px; font-size: 16px; }
.popup-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 14px 12px; border: none; background: #f8f9fa; border-radius: 10px; margin-bottom: 8px; cursor: pointer; font-size: 15px; font-family: inherit; text-align: left; }
.popup-item:active { background: #ecf0f1; }

/* ===== Эмодзи ===== */
.emoji-picker { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-bottom: 14px; }
.emoji-picker button { font-size: 28px; background: #f8f9fa; border: none; border-radius: 12px; padding: 12px 0; cursor: pointer; transition: transform .1s; }
.emoji-picker button:active { transform: scale(.9); background: #ecf0f1; }

/* ===== Список пересылки ===== */
.forward-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.forward-item { display: flex; align-items: center; gap: 12px; padding: 10px 12px; background: #f8f9fa; border: none; border-radius: 10px; cursor: pointer; font-family: inherit; font-size: 15px; text-align: left; }
.forward-item:active { background: #ecf0f1; }
.forward-item .chat-avatar { width: 40px; height: 40px; font-size: 16px; }

/* ===== Участники группы ===== */
.member-check { display: flex; align-items: center; gap: 12px; padding: 10px 12px; border-radius: 10px; cursor: pointer; margin-bottom: 4px; }
.member-check:hover { background: #f8f9fa; }
.member-check input { width: 22px; height: 22px; flex-shrink: 0; accent-color: var(--accent); }

/* ===== Категории документов ===== */
.doc-category {
    margin-bottom: 16px;
    border-bottom: 1px dashed #e1e5ea;
    padding-bottom: 12px;
}
.doc-category:last-of-type { border-bottom: none; }
.doc-cat-header {
    display: flex; justify-content: space-between; align-items: center;
    padding: 8px 12px; background: #f4f6f8; border-radius: 8px;
    margin-bottom: 8px;
}
.doc-cat-name { font-weight: 700; font-size: 14px; color: var(--primary); }
.doc-cat-count {
    background: var(--primary); color: #fff;
    font-size: 11px; font-weight: 700;
    padding: 2px 8px; border-radius: 10px;
}

/* ===== Журнал действий ===== */
.log-list { display: flex; flex-direction: column; gap: 8px; }
.log-item {
    background: #fff; border-radius: 12px; padding: 12px 14px;
    box-shadow: 0 1px 3px rgba(0,0,0,.06);
    border-left: 4px solid var(--primary);
}
.log-top {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 6px; gap: 8px;
}
.log-user { font-weight: 700; font-size: 14px; color: var(--primary); display: flex; align-items: center; }
.log-time { font-size: 11px; color: var(--muted); flex-shrink: 0; }
.log-action { font-size: 14px; margin-bottom: 4px; }
.log-details {
    font-size: 13px; color: #555; background: #f8f9fa;
    padding: 6px 10px; border-radius: 6px; margin-top: 4px;
    word-break: break-word;
}
.log-ip { font-size: 11px; color: var(--muted); margin-top: 6px; font-family: monospace; }

/* ===== Тёмная тема ===== */
[data-theme="dark"] {
    --bg: #14181f;
    --card: #1e242f;
    --text: #e8ecf1;
    --muted: #8e97a6;
    --primary: #4a5d7e;
    --primary-2: #5a6d8e;
}
[data-theme="dark"] body { background: var(--bg); color: var(--text); }
[data-theme="dark"] .card,
[data-theme="dark"] .s-card,
[data-theme="dark"] .chat-row,
[data-theme="dark"] .log-item,
[data-theme="dark"] .notif-item { background: var(--card); color: var(--text); }
[data-theme="dark"] .search { background: var(--card); }
[data-theme="dark"] .search input { color: var(--text); }
[data-theme="dark"] .input { background: #2a3142; color: var(--text); border-color: #3a4152; }
[data-theme="dark"] .input:focus { background: #2f3648; }
[data-theme="dark"] .bottom-nav { background: var(--card); border-color: #2a3142; }
[data-theme="dark"] .msg.other { background: #2a3142; color: var(--text); }
[data-theme="dark"] .reply-quote { background: rgba(255,255,255,.08); }
[data-theme="dark"] .reply-text { color: #b8c0cf; }
[data-theme="dark"] .chip { background: var(--card); color: var(--text); }
[data-theme="dark"] .chip.active { background: var(--primary); }
[data-theme="dark"] .doc-cat-header { background: #2a3142; }
[data-theme="dark"] .file-ico { background: #2a3142; }
[data-theme="dark"] .log-details { background: #2a3142; color: #b8c0cf; }
[data-theme="dark"] .popup-sheet { background: var(--card); color: var(--text); }
[data-theme="dark"] .popup-item { background: #2a3142; color: var(--text); }
[data-theme="dark"] .member-check:hover { background: #2a3142; }
[data-theme="dark"] .forward-item { background: #2a3142; color: var(--text); }
[data-theme="dark"] .chat-box { background: #1a1f28; }
[data-theme="dark"] .chat-input { background: #1e242f; border-color: #2a3142; }
[data-theme="dark"] .chat-input input { background: #2a3142; color: var(--text); border-color: #3a4152; }
[data-theme="dark"] .attach-btn { background: #2a3142; border-color: #3a4152; }
[data-theme="dark"] .reply-bar { background: #1e242f; border-color: #2a3142; }
[data-theme="dark"] .emoji-picker button { background: #2a3142; }
[data-theme="dark"] .reaction-chip { background: #2a3142; border-color: #3a4152; color: var(--text); }
[data-theme="dark"] .reaction-chip.mine { background: #1e3a5f; border-color: var(--blue); }
[data-theme="dark"] .reaction-add { border-color: #3a4152; color: var(--muted); }

/* ===== Статистика ===== */
.stats-grid {
    display: grid; grid-template-columns: repeat(2, 1fr);
    gap: 10px; margin-bottom: 14px;
}
@media (min-width: 600px) { .stats-grid { grid-template-columns: repeat(3, 1fr); } }
.stat-box {
    background: #fff; border-radius: 14px; padding: 16px;
    text-align: center; box-shadow: 0 1px 3px rgba(0,0,0,.08);
    border-top: 4px solid var(--primary);
}
.stat-box.green { border-color: var(--accent); }
.stat-box.red { border-color: var(--red); }
.stat-box.orange { border-color: var(--orange); }
.stat-box.purple { border-color: var(--purple); }
.stat-box.blue { border-color: var(--blue); }
.stat-num { font-size: 28px; font-weight: 800; color: var(--primary); line-height: 1; }
.stat-box.green .stat-num { color: var(--accent); }
.stat-box.red .stat-num { color: var(--red); }
.stat-box.orange .stat-num { color: var(--orange); }
.stat-box.purple .stat-num { color: var(--purple); }
.stat-box.blue .stat-num { color: var(--blue); }
.stat-lbl { font-size: 12px; color: var(--muted); margin-top: 6px; font-weight: 600; }
[data-theme="dark"] .stat-box { background: var(--card); }

/* ===== Диаграмма ===== */
.bar-chart { display: flex; flex-direction: column; gap: 10px; }
.bar-row { display: flex; align-items: center; gap: 10px; }
.bar-label { width: 110px; font-size: 13px; color: var(--muted); flex-shrink: 0; }
.bar-track {
    flex: 1; height: 22px; background: #ecf0f1;
    border-radius: 11px; overflow: hidden;
}
[data-theme="dark"] .bar-track { background: #2a3142; }
.bar-fill { height: 100%; border-radius: 11px; transition: width .5s; }
.bar-fill.green { background: var(--accent); }
.bar-fill.red { background: var(--red); }
.bar-fill.orange { background: var(--orange); }
.bar-fill.purple { background: var(--purple); }
.bar-fill.blue { background: var(--blue); }
.bar-value { width: 40px; text-align: right; font-weight: 700; font-size: 14px; }

/* ===== Профиль ===== */
.success-box {
    background: #e9f7ef; color: var(--accent);
    padding: 12px 16px; border-radius: 10px;
    margin-bottom: 14px; font-size: 14px; font-weight: 600;
    border-left: 4px solid var(--accent);
}
[data-theme="dark"] .success-box { background: #1e3a2e; }