/* ============================================================
   ROSMSG — design tokens + component styles.

   All colors/radii/shadows/spacing live as CSS custom properties on
   :root. Dark theme (body.dark) just overrides the token values — no
   per-component overrides — so any future component inherits the right
   palette automatically. The [hidden] reset at the top is load-bearing:
   `hidden` must beat `display: flex|grid` set elsewhere in the sheet.
   ============================================================ */

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }

:root {
    /* Brand — ROSMSG фиолетово-ягодный с коралловым акцентом. Тёплее
     * прежнего indigo, читается как «русский мессенджер» а не как ещё
     * один Tailwind-стартер. */
    --primary:           #6d4aff;
    --primary-hover:     #5b3ae0;
    --primary-soft:      #ece7ff;
    --primary-on-dark:   #a892ff;
    --accent:            #ff7a59;   /* коралловый акцент для CTA / алертов */
    --accent-soft:       #ffe7de;

    /* Surfaces */
    --bg:                #f4f5fa;
    --bg-elev:           #ffffff;
    --bg-elev-2:         #fafbff;
    --bg-hover:          #eef0f9;
    --bg-subtle:         #f0f2f9;
    --border:            #e2e5f0;
    --border-strong:     #c8ccdd;

    /* Text */
    --text:              #16182a;
    --text-soft:         #4a4e6c;
    --text-muted:        #7f85a0;
    --text-on-primary:   #ffffff;

    /* Semantic */
    --success:           #12b383;
    --warning:           #f59e0b;
    --danger:            #ef4c5b;
    --danger-soft:       #fef0f2;
    --online:            #2bc27a;

    /* Chat specific — «mine» градиент из primary в глубокий фиолет,
     * "theirs" остаются белыми для контраста. */
    --bubble-in:         #ffffff;
    --bubble-in-text:    #16182a;
    --bubble-mine:       linear-gradient(140deg, #7c5cff 0%, #5a3dea 55%, #4a2dd0 100%);
    --bubble-mine-text:  #ffffff;
    --bubble-deleted:    #eef0f8;

    /* Geometry + motion */
    --radius-sm:         6px;
    --radius-md:         10px;
    --radius-lg:         18px;
    --radius-xl:         24px;
    --radius-pill:       999px;
    --shadow-sm:         0 1px 2px rgba(16, 20, 45, 0.06);
    --shadow-md:         0 6px 18px rgba(16, 20, 45, 0.09);
    --shadow-lg:         0 24px 60px rgba(16, 20, 45, 0.18);
    --shadow-bubble:     0 1px 2px rgba(16, 20, 45, 0.06), 0 2px 8px rgba(16, 20, 45, 0.04);
    --ring:              0 0 0 3px rgba(109, 74, 255, 0.24);
    --ease:              cubic-bezier(.2, .8, .2, 1);
    --dur:               160ms;

    /* Layout */
    --sidebar-w:         320px;
    --header-h:          60px;
}

body.dark {
    /* Dark theme — midnight-blue (не чёрный, не серый). Тёплый
     * primary-on-dark держит брендинг, фон получает едва заметный
     * синеватый оттенок, чтобы глаза не уставали. */
    --primary:           #a892ff;
    --primary-hover:     #c4b4ff;
    --primary-soft:      #2a2550;

    --bg:                #0a0d1f;
    --bg-elev:           #141834;
    --bg-elev-2:         #1a1f3e;
    --bg-hover:          #222848;
    --bg-subtle:         #181d3a;
    --border:            #2a3055;
    --border-strong:     #3b4270;

    --text:              #ebeef8;
    --text-soft:         #adb3ce;
    --text-muted:        #757a98;

    --accent:            #ff9478;
    --accent-soft:       #3a1f18;

    --bubble-in:         #1e2440;
    --bubble-in-text:    #ebeef8;
    --bubble-mine:       linear-gradient(140deg, #8b6dff 0%, #6a4aea 55%, #5a3dd0 100%);
    --bubble-deleted:    #242a48;

    --shadow-sm:         0 1px 2px rgba(0, 0, 0, 0.5);
    --shadow-md:         0 8px 22px rgba(0, 0, 0, 0.45);
    --shadow-lg:         0 24px 60px rgba(0, 0, 0, 0.6);
    --shadow-bubble:     0 1px 3px rgba(0, 0, 0, 0.5);
    --ring:              0 0 0 3px rgba(168, 146, 255, 0.3);
}

html, body { height: 100%; }
body {
    margin: 0;
    font: var(--root-font-size, 14px)/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    color: var(--text);
    background: var(--bg);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
#app { height: 100vh; display: flex; }

/* ---------- Typography primitives ---------- */
h1, h2, h3 { margin: 0; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.muted { color: var(--text-muted); font-size: 12px; }

/* ---------- Buttons ---------- */
button {
    appearance: none;
    -webkit-appearance: none;
    padding: 9px 16px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    background: var(--primary);
    color: var(--text-on-primary);
    cursor: pointer;
    font: 600 13px/1 inherit;
    letter-spacing: 0.01em;
    transition: background var(--dur) var(--ease), transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease);
}
button:hover:not(:disabled)      { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 3px 8px rgba(79, 70, 229, 0.25); }
button:active:not(:disabled)     { transform: translateY(0); box-shadow: none; }
button.secondary:hover:not(:disabled), button.link:hover:not(:disabled), .icon-btn:hover:not(:disabled) { box-shadow: none; transform: none; }
button:focus-visible             { outline: none; box-shadow: var(--ring); }
button:disabled                  { opacity: .45; cursor: not-allowed; }

button.link {
    background: transparent;
    color: var(--primary);
    padding: 6px 8px;
    border-radius: var(--radius-sm);
    font-weight: 500;
}
button.link:hover:not(:disabled) { background: var(--primary-soft); }
button.secondary {
    background: var(--bg-elev);
    color: var(--text);
    border-color: var(--border);
}
button.secondary:hover:not(:disabled) { background: var(--bg-hover); }
button.danger  { background: var(--danger); }
button.danger:hover:not(:disabled) { background: #dc2626; }

/* Icon-only buttons */
.icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px; height: 32px;
    padding: 0;
    background: transparent;
    color: var(--text-soft);
    border-radius: var(--radius-md);
}
.icon-btn:hover:not(:disabled) { background: var(--bg-hover); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; display: block; }

/* ---------- Inputs ---------- */
input, textarea, select {
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    transition: border-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease), background var(--dur) var(--ease);
}
input::placeholder, textarea::placeholder { color: var(--text-muted); }
input:focus, textarea:focus, select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: var(--ring);
}

.card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-md);
    text-align: left;
}
.card label {
    display: block;
    margin: 0 0 4px;
    font-size: 12px;
    font-weight: 600;
    color: var(--text-soft);
    letter-spacing: 0.02em;
}
.card label input, .card label textarea { width: 100%; margin-top: 4px; }
.card > label + label { margin-top: 12px; }
.row { display: flex; gap: 10px; margin-top: 16px; }
hr { border: 0; border-top: 1px solid var(--border); margin: 16px 0 12px; }

/* ============================================================
   AUTH VIEW — centered card on a subtle gradient canvas.
   ============================================================ */
#auth-view {
    margin: auto;
    width: 380px;
    max-width: 92vw;
    text-align: center;
    padding: 24px;
    position: relative;
    z-index: 1;
    animation: authIn 420ms var(--ease) both;
}
@keyframes authIn {
    from { opacity: 0; transform: translateY(16px) scale(.97); }
    to   { opacity: 1; transform: none; }
}
#auth-view::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(1200px 600px at 15% -10%,  rgba(99, 102, 241, 0.18), transparent 60%),
        radial-gradient(900px 500px  at 110% 110%, rgba(14, 165, 233, 0.14), transparent 60%);
    z-index: -1;
    pointer-events: none;
}
#auth-view h1 {
    font-size: 32px;
    letter-spacing: 0.14em;
    margin: 0 0 6px;
    background: linear-gradient(135deg, var(--primary) 0%, #0ea5e9 100%);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
}
#auth-view .subtitle {
    color: var(--text-soft);
    font-size: 13px;
    margin: 0 0 24px;
}
#auth-view .row button { flex: 1; }
#auth-status { margin: 12px 0 0; min-height: 1em; }
#auth-status.error { color: var(--danger); }
#auth-status.ok    { color: var(--success); }

/* ============================================================
   CHAT VIEW
   ============================================================ */
#chat-view { flex: 1; display: flex; min-width: 0; }

#chat-view aside {
    width: var(--sidebar-w);
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    /* Чуть теплее основного фона — сайдбар читается как «стена чатов», а
     * messages-pane — как «сцена». Очень лёгкий вертикальный градиент от
     * bg-elev внизу до bg-elev-2 сверху даёт глубину без веса. */
    background: linear-gradient(180deg, var(--bg-elev-2) 0%, var(--bg-elev) 100%);
    display: flex;
    flex-direction: column;
    min-height: 0;
    position: relative;
}

/* Drag handle on the sidebar's right edge. Mouse / touch drag persists
   the new width in localStorage so reloads remember the user's pick. */
.sidebar-resizer {
    position: absolute;
    top: 0;
    right: -3px;
    bottom: 0;
    width: 6px;
    cursor: col-resize;
    z-index: 3;
    background: transparent;
    transition: background var(--dur) var(--ease);
}
.sidebar-resizer:hover,
.sidebar-resizer.dragging { background: color-mix(in srgb, var(--primary) 40%, transparent); }
.sidebar-resizer:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: -1px;
}
@media (max-width: 720px) { .sidebar-resizer { display: none; } }

.me {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
}
.me-info { min-width: 0; overflow: hidden; flex: 1; }
/* Own-avatar chip in the sidebar me-block. Clicking opens the profile
   dialog (via JS) so the chip doubles as a settings entry point; cursor
   reflects that. Sized to match #chats-list .avatar for visual rhythm. */
.me-avatar-slot { cursor: pointer; flex-shrink: 0; }
.me-avatar-slot .avatar { width: 36px; height: 36px; font-size: 13px; }

/* Peer profile peek dialog — compact card with avatar + names stacked
   horizontally, bio on its own paragraph, and actions in a row. Reuses
   the existing .card styling; these rules just do the layout inside. */
.user-profile-card { min-width: 320px; max-width: 420px; }
.user-profile-header {
    display: flex;
    gap: 12px;
    align-items: center;
    margin-bottom: 12px;
}
.user-profile-avatar-slot .avatar { width: 56px; height: 56px; font-size: 20px; }
.user-profile-names { min-width: 0; }
.user-profile-names strong { font-size: 16px; display: block; }
.user-profile-bio {
    margin: 6px 0 12px;
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-soft);
}
.user-profile-bio:empty { display: none; }
.me strong { display: block; font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* С десятком icon-кнопок в .me-actions эта ширина бывает крошечной, и без
   nowrap текст "@sergey · id=2" разламывался на три строки — оставался
   одинокий "·" по центру. nowrap+ellipsis — одна строка, с троеточием
   если не хватает. */
#me-meta { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-actions { display: flex; gap: 2px; }

.sidebar-tabs { padding: 12px; border-bottom: 1px solid var(--border); position: relative; }
#search-input {
    width: 100%;
    padding: 9px 14px 9px 34px;
    border-radius: var(--radius-pill);
    background: var(--bg) url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238a8fa5' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><circle cx='11' cy='11' r='7'/><path d='m21 21-4.3-4.3'/></svg>") 10px center / 16px no-repeat;
}
#search-results {
    position: absolute;
    left: 12px; right: 12px; top: 54px;
    background: var(--bg-elev);
    list-style: none;
    margin: 0;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    max-height: 280px;
    overflow: auto;
    box-shadow: var(--shadow-lg);
    z-index: 5;
}
#search-results:empty { display: none; }
#search-results li { padding: 8px 10px; cursor: pointer; border-radius: var(--radius-sm); }
#search-results li:hover { background: var(--primary-soft); }

#new-chat-form { padding: 10px 12px; gap: 6px; margin: 0; }
#new-chat-form input { flex: 1; padding: 8px 10px; font-size: 13px; }
#new-chat-form button { padding: 8px 12px; font-size: 12px; }

#chats-list { list-style: none; margin: 0; padding: 6px; overflow: auto; flex: 1; min-height: 0; }
#chats-list li {
    padding: 10px 12px;
    cursor: pointer;
    border-radius: var(--radius-md);
    display: flex;
    gap: 10px;
    align-items: center;
    position: relative;
    transition: background var(--dur) var(--ease);
}
#chats-list li:hover        { background: var(--bg-hover); }
#chats-list li.active       { background: var(--primary-soft); }
#chats-list li.active::before {
    content: '';
    position: absolute;
    left: 0; top: 10px; bottom: 10px;
    width: 3px;
    border-radius: 3px;
    background: var(--primary);
}
body.dark #chats-list li.active { background: var(--bg-hover); }
#chats-list .chat-title-block { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
#chats-list .chat-title-row { display: flex; align-items: baseline; gap: 8px; min-width: 0; }
#chats-list .chat-title {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}
#chats-list .chat-time {
    font-size: 11px;
    flex-shrink: 0;
    color: var(--text-muted);
}
#chats-list .chat-preview {
    font-size: 12px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
#chats-list li.active .chat-preview { color: var(--text); opacity: .7; }

/* Muted chat: soften the title and grey-out the unread badge so the
   user can spot noisy rooms at a glance. The small 🔕 in the title
   row is placed next to the name. */
#chats-list li.chat-muted .chat-title-text { color: var(--text-muted); }
#chats-list .chat-mute-icon,
#chats-list .chat-pin-icon {
    font-size: 11px;
    flex-shrink: 0;
    opacity: 0.7;
}
#chats-list .badge.badge-muted {
    background: var(--border) !important;
    color: var(--text-muted) !important;
    box-shadow: none !important;
    animation: none !important;
}
/* Pinned chats get a faint accent stripe on the leading edge to make the
   group visually separable from the rest of the list. */
#chats-list li.chat-pinned {
    background: linear-gradient(90deg, color-mix(in srgb, var(--primary) 8%, transparent), transparent 35%);
}
#chats-list li.chat-pinned::before {
    content: '';
    position: absolute;
    left: 0; top: 8px; bottom: 8px;
    width: 3px;
    background: var(--primary);
    border-radius: 0 3px 3px 0;
    opacity: 0.6;
}
#chats-list li { position: relative; }

/* Draft indicator: preview text rendered in italic primary-colour with
   a leading "✏ " glyph added via ::before so it stands out from the
   usual last-message preview. */
#chats-list .chat-preview.has-draft {
    color: var(--primary);
    font-style: italic;
}
#chats-list .chat-preview.has-draft::before {
    content: '✏ ';
    font-style: normal;
}
/* Typing-in-progress preview: italic + accent so it's visibly different
   from a draft (draft shows *your* unsent text) and from the usual
   last-message row. Beats the preview text win when both would apply
   because activity RIGHT NOW is more relevant than the last message. */
#chats-list .chat-preview.is-typing {
    color: var(--primary);
    font-style: italic;
}

/* Online presence dot — small green circle on the avatar's bottom-right. */
.avatar.online::after {
    content: '';
    position: absolute;
    right: -1px;
    bottom: -1px;
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #22c55e;
    box-shadow: 0 0 0 2px var(--bg-elev);
    animation: presencePulse 2.2s ease-in-out infinite;
}
.avatar { position: relative; }
body.dark .avatar.online::after { box-shadow: 0 0 0 2px var(--bg); }
@keyframes presencePulse {
    0%, 100% { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 0 rgba(34,197,94,.55); }
    50%      { box-shadow: 0 0 0 2px var(--bg-elev), 0 0 0 4px rgba(34,197,94,0); }
}

/* Scroll-to-bottom floating button — visible only while user is scrolled up */
.scroll-to-bottom {
    position: absolute;
    right: 20px;
    bottom: 96px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--primary);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    box-shadow: var(--shadow-md);
    transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease);
    z-index: 4;
    animation: scrollBtnIn var(--dur) var(--ease);
}
.scroll-to-bottom:hover { transform: translateY(-2px); }
.scroll-to-bottom svg { width: 20px; height: 20px; }
.scroll-to-bottom[hidden] { display: none; }
.scroll-to-bottom .scroll-unread {
    position: absolute;
    top: -6px;
    right: -6px;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 20px;
    text-align: center;
    box-shadow: 0 1px 3px rgba(0,0,0,.25);
    animation: scrollBtnIn var(--dur) var(--ease);
}
.scroll-to-bottom .scroll-unread[hidden] { display: none; }
@keyframes scrollBtnIn {
    from { opacity: 0; transform: translateY(8px) scale(.9); }
    to   { opacity: 1; transform: none; }
}
.badge {
    background: var(--primary);
    color: var(--text-on-primary);
    border-radius: var(--radius-pill);
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    min-width: 20px;
    text-align: center;
    line-height: 1.4;
}

/* Main pane */
#chat-view main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); position: relative; }
#chat-header {
    min-height: var(--header-h);
    padding: 12px 20px;
    border-bottom: 1px solid var(--border);
    /* backdrop-filter добавляет лёгкую «матовую» глубину поверх pattern'а
     * сообщений, когда пользователь скроллит — имитирует стеклянную панель
     * Safari/iOS без потери читаемости. */
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
    backdrop-filter: saturate(140%) blur(8px);
    -webkit-backdrop-filter: saturate(140%) blur(8px);
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
    position: relative;
    z-index: 2;
}
.chat-header-main { display: flex; gap: 10px; align-items: baseline; min-width: 0; }
#chat-title { font-weight: 600; font-size: 15px; letter-spacing: -0.005em; }
.chat-header-actions { display: flex; gap: 4px; }

.pins-panel, .search-panel {
    border-bottom: 1px solid var(--border);
    background: var(--bg-elev-2);
    max-height: 260px;
    overflow: auto;
}
.pins-panel header, .search-panel header {
    padding: 10px 14px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 13px;
}
.search-panel header input[type=text], .search-panel header #chat-search-input {
    flex: 1;
    padding: 7px 12px;
    font-size: 13px;
    border-radius: var(--radius-pill);
}
.search-scope {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    color: var(--text-muted);
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    padding: 4px 8px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    transition: background 120ms var(--ease);
}
.search-scope:hover { background: var(--bg-hover); }
.search-scope input { margin: 0; }
.search-hit-chat {
    display: inline-block;
    margin-right: 6px;
    padding: 1px 8px;
    border-radius: var(--radius-pill);
    background: var(--primary-soft);
    color: var(--primary);
    font-size: 11px;
    font-weight: 600;
}
.search-status { font-style: italic; }

/* ---- Right-click context menu on messages ------------------------ */
.ctx-menu {
    position: fixed;
    z-index: 300;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 4px;
    min-width: 180px;
    animation: popIn 140ms var(--ease);
}
.ctx-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 7px 10px;
    border: 0;
    background: transparent;
    color: var(--text);
    font-size: 13px;
    text-align: left;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background 120ms var(--ease);
}
.ctx-item:hover { background: var(--primary-soft); }
.ctx-item.danger { color: #ef4444; }
.ctx-item.danger:hover { background: rgba(239, 68, 68, 0.12); }
.ctx-icon { width: 18px; text-align: center; }
.pins-panel ul, .search-panel ul { list-style: none; margin: 0; padding: 4px; }
.pins-panel li, .search-panel li {
    padding: 8px 10px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    gap: 8px;
    justify-content: space-between;
    align-items: center;
    transition: background var(--dur) var(--ease);
}
.pins-panel li:hover, .search-panel li:hover { background: var(--bg-hover); }

/* Upgraded pin item layout: name+time on top, body middle, unpin button
   on the right. Fade on remove handled inline. */
.pin-item {
    display: grid !important;
    grid-template-columns: 1fr auto;
    grid-template-rows: auto auto;
    gap: 2px 8px !important;
    align-items: start !important;
    transition: opacity 180ms var(--ease), background var(--dur) var(--ease);
}
.pin-head {
    grid-column: 1;
    grid-row: 1;
    display: flex;
    gap: 8px;
    align-items: baseline;
    min-width: 0;
}
.pin-head strong { font-size: 13px; }
.pin-time { font-size: 11px; }
.pin-body {
    grid-column: 1;
    grid-row: 2;
    font-size: 13px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}
.pin-unpin {
    grid-column: 2;
    grid-row: 1 / span 2;
    align-self: center;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    width: 24px; height: 24px;
    color: var(--muted);
    cursor: pointer;
    font-size: 11px;
    line-height: 1;
    transition: color 120ms var(--ease), border-color 120ms var(--ease);
}
.pin-unpin:hover { color: var(--danger, #ef4444); border-color: var(--danger, #ef4444); }
.pins-empty { justify-content: center !important; text-align: center; color: var(--text-muted); }

/* ---- Emoji picker panel ------------------------------------------ */
.emoji-btn {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    width: 36px; height: 36px;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    transition: background 120ms var(--ease);
}
.emoji-btn:hover { background: var(--bg-hover); }
.emoji-panel {
    position: absolute;
    bottom: 68px;
    right: 12px;
    z-index: 90;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    padding: 8px;
    max-width: 320px;
    max-height: 340px;
    overflow-y: auto;
    animation: popIn 160ms var(--ease);
}
.emoji-panel[hidden] { display: none; }
.emoji-section-label {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    padding: 4px 6px 2px;
}
.emoji-row {
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 2px;
}
.emoji-cell {
    background: transparent;
    border: 0;
    font-size: 22px;
    line-height: 1;
    padding: 6px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: background 120ms var(--ease), transform 140ms var(--ease);
}
.emoji-cell:hover {
    background: var(--primary-soft);
    transform: scale(1.15);
}
@media (max-width: 720px) {
    .emoji-panel { right: 8px; left: 8px; max-width: none; }
}

/* ---------- Empty states ---------- */
/* Sidebar: when the user has no chats yet, show a short hint right below
   the "ID собеседника" form so they know what to do next. */
#chats-list:empty::after {
    content: 'Пока нет чатов.\AНайдите пользователя выше или создайте чат по ID.';
    display: block;
    white-space: pre-wrap;
    padding: 24px 16px;
    color: var(--text-muted);
    text-align: center;
    font-size: 13px;
    line-height: 1.5;
}
/* Main pane: when no chat is active, the empty message list becomes an
   onboarding hero. Uses :has() so we don't need any JS toggling. */
#messages-list:empty {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px;
}
/* The icon shape is declared via CSS mask so it inherits currentColor
   via a plain background, giving us a theme-aware duotone without any
   extra images. */
#messages-list:empty::before {
    content: '';
    display: block;
    width: 72px; height: 72px;
    margin: 0 auto 16px;
    background: var(--primary);
    opacity: .85;
    mask:         url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'><path d='M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H8l-4 4V6a2 2 0 0 1 2-2zm3 6h10v2H7v-2zm0 4h7v2H7v-2z'/></svg>") center / contain no-repeat;
    -webkit-mask: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='currentColor'><path d='M4 4h16a2 2 0 0 1 2 2v12a2 2 0 0 1-2 2H8l-4 4V6a2 2 0 0 1 2-2zm3 6h10v2H7v-2zm0 4h7v2H7v-2z'/></svg>") center / contain no-repeat;
}
#messages-list:empty::after {
    content: 'Пока тут тихо.\A Выберите чат слева или создайте новый.';
    white-space: pre-wrap;
    color: var(--text-soft);
    font-size: 14px;
    text-align: center;
    max-width: 300px;
    line-height: 1.5;
}
#messages-list:empty { flex-direction: column; }

/* ---------- Empty chat splash ----------
   Shown in the main pane when no chat is selected (initial load,
   after leave/delete). Covers the message-list area so new users see
   a welcome + call-to-action rather than a blank void. */
.chat-empty-splash {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 32px 16px;
    text-align: center;
    color: var(--text-soft);
}
.chat-empty-splash[hidden] { display: none; }
.chat-empty-splash .splash-icon {
    font-size: 56px;
    line-height: 1;
    opacity: 0.7;
}
.chat-empty-splash h2 {
    margin: 0;
    font-size: 22px;
    color: var(--text);
}
.chat-empty-splash p {
    margin: 0;
    max-width: 320px;
    line-height: 1.5;
}
.chat-empty-splash .splash-actions {
    display: flex;
    gap: 10px;
    margin-top: 8px;
    flex-wrap: wrap;
    justify-content: center;
}
.chat-empty-splash .splash-btn {
    padding: 9px 16px;
    border-radius: var(--radius-pill);
}

/* ---------- Messages ---------- */
#messages-list {
    flex: 1;
    list-style: none;
    margin: 0;
    padding: 16px;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 4px;
    min-height: 0;
    scrollbar-gutter: stable;
    background-color: var(--bg);
    background-image: none;
    background-size: auto;
}

/* Wallpapers. Default (wp-dots) paints the Telegram-like dot pattern.
 * Other variants are opt-in via the profile dialog and persist in
 * localStorage under `rosmsg.wallpaper`. All rules scope off <body> so
 * one active class wins regardless of light/dark theme. */
body.wp-dots #messages-list {
    background-image:
        radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--text) 5%, transparent) 1px, transparent 0);
    background-size: 22px 22px;
}
body.dark.wp-dots #messages-list {
    background-image:
        radial-gradient(circle at 1px 1px, rgba(255,255,255,0.04) 1px, transparent 0);
}
body.wp-plain #messages-list {
    background-image: none;
}
body.wp-grid #messages-list {
    background-image:
        linear-gradient(to right,  color-mix(in srgb, var(--text) 4%, transparent) 1px, transparent 1px),
        linear-gradient(to bottom, color-mix(in srgb, var(--text) 4%, transparent) 1px, transparent 1px);
    background-size: 28px 28px;
}
body.dark.wp-grid #messages-list {
    background-image:
        linear-gradient(to right,  rgba(255,255,255,0.035) 1px, transparent 1px),
        linear-gradient(to bottom, rgba(255,255,255,0.035) 1px, transparent 1px);
}
body.wp-dawn #messages-list {
    background-image:
        radial-gradient(1200px 600px at 15% -10%,  rgba(255, 122, 89, 0.18), transparent 60%),
        radial-gradient(900px 500px  at 110% 110%, rgba(109, 74, 255, 0.14), transparent 60%);
    background-size: auto;
}
body.dark.wp-dawn #messages-list {
    background-image:
        radial-gradient(1200px 600px at 15% -10%,  rgba(255, 122, 89, 0.12), transparent 60%),
        radial-gradient(900px 500px  at 110% 110%, rgba(109, 74, 255, 0.10), transparent 60%);
}
body.wp-midnight #messages-list {
    background-color: #0a0d1f;
    color-scheme: dark;
    background-image:
        radial-gradient(900px 500px at 80% -10%, rgba(109, 74, 255, 0.22), transparent 60%),
        radial-gradient(800px 500px at -10% 110%, rgba(14, 165, 233, 0.18), transparent 60%);
    background-size: auto;
}
#messages-list::-webkit-scrollbar          { width: 10px; }
#messages-list::-webkit-scrollbar-thumb    { background: var(--border); border-radius: 10px; border: 2px solid var(--bg); }
#messages-list::-webkit-scrollbar-thumb:hover { background: var(--border-strong); }

#messages-list li {
    max-width: 64%;
    padding: 10px 14px;
    border-radius: var(--radius-lg);
    background: var(--bubble-in);
    color: var(--bubble-in-text);
    word-break: break-word;
    position: relative;
    box-shadow: var(--shadow-bubble);
    animation: bubbleIn 180ms var(--ease) both;
    transition: transform 180ms var(--ease), box-shadow 180ms var(--ease);
}
#messages-list li:hover {
    box-shadow: 0 2px 6px rgba(16, 20, 45, 0.08), 0 8px 24px rgba(16, 20, 45, 0.06);
}
body.dark #messages-list li:hover {
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
}
#messages-list li.mine {
    align-self: flex-end;
    background: var(--bubble-mine);
    color: var(--bubble-mine-text);
    border-bottom-right-radius: 6px;
    /* Лёгкая колоритная тень под «своими» пузырями — подчёркивает
     * доминанту primary в интерфейсе. */
    box-shadow: 0 1px 2px rgba(90, 61, 234, 0.18), 0 6px 18px rgba(90, 61, 234, 0.22);
}
#messages-list li.mine:hover {
    box-shadow: 0 2px 4px rgba(90, 61, 234, 0.22), 0 10px 28px rgba(90, 61, 234, 0.28);
}
#messages-list li:not(.mine):not(.date-sep):not(.deleted) { border-bottom-left-radius: 6px; }
#messages-list li.deleted {
    background: var(--bubble-deleted);
    color: var(--text-muted);
    font-style: italic;
    box-shadow: none;
}
#messages-list li .sender {
    font-size: 11px;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 2px;
}
#messages-list li.mine .sender { color: rgba(255,255,255,.85); }
#messages-list li .meta { font-size: 10.5px; color: var(--text-muted); margin-top: 4px; letter-spacing: 0.02em; }
#messages-list li.mine .meta { color: rgba(255,255,255,.75); }
#messages-list li.mine .meta .receipt {
    font-weight: 700;
    letter-spacing: -1px;
    margin-left: 2px;
    transition: color 160ms var(--ease);
}
#messages-list li.mine .meta .receipt.read { color: #86efac; }
body.dark #messages-list li.mine .meta .receipt.read { color: #4ade80; }
#messages-list li .reply-quote {
    font-size: 12px;
    border-left: 3px solid var(--primary);
    padding: 4px 10px;
    margin: 0 0 6px;
    background: var(--primary-soft);
    border-radius: var(--radius-sm);
    color: var(--text-soft);
    cursor: pointer;
    transition: filter 120ms var(--ease);
}
#messages-list li .reply-quote:hover { filter: brightness(0.96); }
body.dark #messages-list li .reply-quote:hover { filter: brightness(1.15); }

/* Flash highlight when a reply-quote jumps to the original. */
#messages-list li.jump-flash {
    animation: jumpFlash 1.4s var(--ease);
}
@keyframes jumpFlash {
    0%   { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); }
    15%  { box-shadow: 0 0 0 4px rgba(79, 70, 229, 0.55); }
    100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0); }
}
#messages-list li.mine .reply-quote {
    background: rgba(255,255,255,.14);
    border-left-color: rgba(255,255,255,.8);
    color: rgba(255,255,255,.92);
}
#messages-list li .body { white-space: pre-wrap; line-height: 1.45; word-break: break-word; }
#messages-list li .body a {
    color: inherit;
    text-decoration: underline;
    text-decoration-thickness: 1px;
    text-underline-offset: 2px;
}
#messages-list li .body a:hover { text-decoration-thickness: 2px; }
#messages-list li.mine .body a { color: #f0f0ff; }

/* Long-message collapse — bodies flagged as too long clip to ~14 lines
   with a soft fade at the bottom. The "Показать полностью" toggle lives
   just below the bubble and flips a class to drop the clip. */
#messages-list li .body.long-collapsed {
    max-height: 20em;
    overflow: hidden;
    position: relative;
    mask-image: linear-gradient(to bottom, #000 80%, transparent);
    -webkit-mask-image: linear-gradient(to bottom, #000 80%, transparent);
}
#messages-list li .body.long-expanded { max-height: none; }
#messages-list li .long-toggle {
    align-self: flex-start;
    margin-top: 6px;
    background: transparent;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    padding: 2px 0;
}
#messages-list li .long-toggle:hover { text-decoration: underline; }
#messages-list li.mine .long-toggle { color: #e0e7ff; }

/* Search highlight inside message bodies */
#messages-list li .body mark {
    background: #fde68a;
    color: #1f2937;
    padding: 0 2px;
    border-radius: 3px;
}
body.dark #messages-list li .body mark {
    background: #facc15;
    color: #111827;
}

/* Click-to-focus flash when jumping to a search result */
#messages-list li.flash {
    animation: msgFlash 1.2s var(--ease);
}
@keyframes msgFlash {
    0%   { box-shadow: 0 0 0 0 rgba(99,102,241,.55), var(--shadow-sm); }
    30%  { box-shadow: 0 0 0 6px rgba(99,102,241,.25), var(--shadow-md); }
    100% { box-shadow: 0 0 0 0 rgba(99,102,241,0),    var(--shadow-sm); }
}

/* Unread separator — rendered as a full-width ruled line with label */
#messages-list li.unread-sep {
    align-self: stretch;
    background: transparent;
    color: var(--primary);
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    padding: 4px 0;
    margin: 8px 0 4px;
    text-align: center;
    position: relative;
    animation: unreadIn var(--dur) var(--ease);
}
#messages-list li.unread-sep::before,
#messages-list li.unread-sep::after {
    content: '';
    position: absolute;
    top: 50%;
    width: calc(50% - 80px);
    height: 1px;
    background: linear-gradient(90deg, transparent, var(--primary) 40%, var(--primary) 60%, transparent);
    opacity: .45;
}
#messages-list li.unread-sep::before { left: 0; }
#messages-list li.unread-sep::after  { right: 0; }
@keyframes unreadIn {
    from { opacity: 0; transform: translateY(-4px); }
    to   { opacity: 1; transform: none; }
}

@keyframes bubbleIn {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: none; }
}

.reactions { margin-top: 6px; display: flex; gap: 4px; flex-wrap: wrap; }
.reaction-chip {
    background: var(--bg-hover);
    color: var(--text);
    padding: 2px 8px;
    font-size: 12px;
    border-radius: var(--radius-pill);
    border: 1px solid transparent;
    transition: transform var(--dur) var(--ease), border-color var(--dur) var(--ease);
}
.reaction-chip:hover   { transform: scale(1.06); }
.reaction-chip.mine    { background: #fef3c7; color: #92400e; border-color: #fcd34d; }
#messages-list li.mine .reaction-chip       { background: rgba(255,255,255,.18); color: #fff; }
#messages-list li.mine .reaction-chip.mine  { background: #fde68a; color: #713f12; border-color: transparent; }

.actions {
    position: absolute;
    top: -14px; right: 10px;
    display: none;
    gap: 2px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    padding: 2px;
    box-shadow: var(--shadow-md);
}
#messages-list li:hover .actions { display: flex; }
.msg-action {
    background: transparent;
    color: var(--text-soft);
    padding: 4px 8px;
    font-size: 12px;
    border-radius: var(--radius-pill);
    font-weight: 500;
}
.msg-action:hover { background: var(--bg-hover); color: var(--text); }

/* Empty state in message area */
#chat-title:has(+ .muted) { color: var(--text-soft); font-weight: 500; }

/* Typing / reply previews */
#typing-indicator {
    padding: 4px 20px;
    font-style: italic;
    color: var(--text-muted);
    font-size: 12px;
    display: flex;
    align-items: center;
    gap: 8px;
}
.typing-avatars {
    display: inline-flex;
    align-items: center;
}
.typing-avatars .avatar {
    width: 20px !important;
    height: 20px !important;
    font-size: 9px !important;
    border: 2px solid var(--bg) !important;
    margin-left: -6px;
}
.typing-avatars .avatar:first-child { margin-left: 0; }

/* Connection-state dot in the chat header — tri-state: online (green,
   gently pulsing), connecting (amber, fast pulse), offline (red solid).
   Sits next to the chat title so it's always visible. */
.conn-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
    margin-right: 8px;
    box-shadow: 0 0 0 0 transparent;
}
.conn-dot[data-state="online"]     { background: #10b981; animation: connPulse 2.2s ease-in-out infinite; }
.conn-dot[data-state="connecting"] { background: #f59e0b; animation: connPulse 0.9s ease-in-out infinite; }
.conn-dot[data-state="offline"]    { background: #dc2626; animation: none; }
@keyframes connPulse {
    0%, 100% { box-shadow: 0 0 0 0 currentColor; opacity: 1; }
    50%      { box-shadow: 0 0 0 4px transparent; opacity: 0.7; }
}

/* Bio char counter — inline muted text right-aligned below the textarea.
   Warn state (>240) turns amber, full (=280) turns red. */
.bio-count {
    display: block;
    text-align: right;
    font-size: 11px;
    margin-top: 2px;
}
.bio-count-warn { color: #d97706; }
.bio-count-full { color: #dc2626; font-weight: 600; }

/* Current-session highlight in sessions list + "текущий" badge. */
.sessions-list li.session-current {
    background: var(--primary-soft);
}
.session-badge-current {
    display: inline-block;
    margin-left: 8px;
    padding: 1px 8px;
    font-size: 10px;
    font-weight: 700;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    background: var(--primary);
    color: #fff;
    border-radius: var(--radius-pill);
}
.typing-dots {
    display: inline-flex;
    gap: 3px;
}
.typing-dots i {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: var(--primary);
    opacity: .5;
    animation: typingBounce 1.1s infinite var(--ease);
}
.typing-dots i:nth-child(2) { animation-delay: .15s; }
.typing-dots i:nth-child(3) { animation-delay: .3s; }
@keyframes typingBounce {
    0%, 60%, 100% { transform: translateY(0);   opacity: .4; }
    30%           { transform: translateY(-4px); opacity: 1; }
}
.reply-preview, .attach-preview {
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-elev-2);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-soft);
}
.attach-preview { flex-wrap: wrap; }

/* Send form */
#send-form {
    display: flex;
    gap: 8px;
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    /* Тот же «matte glass» трюк, что у chat-header — композер «висит»
     * поверх dot-pattern'а, edges не дерутся с фоном сообщений. */
    background: color-mix(in srgb, var(--bg-elev) 94%, transparent);
    backdrop-filter: saturate(140%) blur(8px);
    -webkit-backdrop-filter: saturate(140%) blur(8px);
    align-items: center;
    position: relative;
    z-index: 2;
}
#send-form input {
    flex: 1;
    padding: 11px 16px;
    border-radius: var(--radius-pill);
    background: var(--bg);
}
#send-form button[type=submit] {
    padding: 10px 18px;
    border-radius: var(--radius-pill);
}
/* "No chat selected" state: the composer is physically here but has
   nowhere to send to. Dim the row and block pointer events on the
   helper buttons (attach / emoji / record) so their hover states don't
   light up and mislead. The <button> + <input disabled> attributes
   still carry the semantic meaning; this is purely visual. */
#send-form.composer-empty { opacity: 0.55; }
#send-form.composer-empty .attach-btn,
#send-form.composer-empty .emoji-btn,
#send-form.composer-empty .record-btn {
    pointer-events: none;
    cursor: not-allowed;
}
.attach-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px; height: 36px;
    border-radius: 50%;
    cursor: pointer;
    color: var(--text-soft);
    transition: color var(--dur) var(--ease), background var(--dur) var(--ease);
}
.attach-btn:hover { color: var(--primary); background: var(--primary-soft); }
.attach-btn svg { width: 18px; height: 18px; }

/* ---------- Dialogs ---------- */
dialog {
    border: 0;
    border-radius: var(--radius-lg);
    padding: 0;
    background: var(--bg-elev);
    color: var(--text);
    box-shadow: var(--shadow-lg);
    max-width: 92vw;
}
dialog::backdrop { background: rgba(15, 17, 40, 0.45); backdrop-filter: blur(4px); }
.profile-form { min-width: 360px; padding: 0; }
.profile-form h2 { margin: 0 0 4px; font-size: 18px; }
.profile-form h3 { margin: 0 0 4px; font-size: 13px; color: var(--text-soft); font-weight: 600; letter-spacing: 0.02em; }

/* Live preview of avatar + display name + ID at the top of the profile
   dialog. Re-renders on every input event so the user sees what they're
   about to save. Falls back to initials if the avatar URL fails to load. */
.profile-preview {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 10px 12px;
    margin-bottom: 10px;
    background: var(--primary-soft);
    border-radius: var(--radius);
}
.profile-avatar-preview {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    overflow: hidden;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-weight: 700;
    font-size: 18px;
    flex-shrink: 0;
}
.profile-avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.profile-preview-meta { min-width: 0; flex: 1; }
.profile-preview-name {
    font-weight: 600;
    font-size: 15px;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.profile-preview-id {
    font-size: 12px;
    display: flex;
    gap: 8px;
    align-items: center;
    margin-top: 2px;
}
.profile-preview-id .link {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    padding: 0;
    font-size: 12px;
}
.profile-preview-id .link:hover { text-decoration: underline; }

/* Wallpaper picker — row of thumbnail chips inside the profile dialog.
 * Each chip previews the pattern at 80x56 with a label underneath. The
 * active chip gets a primary-coloured ring so the current choice is
 * obvious at a glance. */
.wallpaper-picker {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
    gap: 8px;
    margin: 4px 0 8px;
}
.wallpaper-chip {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 6px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-md, 10px);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.wallpaper-chip:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.wallpaper-chip.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 35%, transparent);
}
.wallpaper-chip-preview {
    display: block;
    height: 44px;
    border-radius: 8px;
    background-color: var(--bg);
    background-image: none;
    background-size: auto;
}
.wp-preview-dots .wallpaper-chip-preview {
    background-image:
        radial-gradient(circle at 1px 1px, color-mix(in srgb, var(--text) 10%, transparent) 1px, transparent 0);
    background-size: 10px 10px;
}
.wp-preview-plain .wallpaper-chip-preview { background-image: none; }
.wp-preview-grid .wallpaper-chip-preview {
    background-image:
        linear-gradient(to right,  color-mix(in srgb, var(--text) 8%, transparent) 1px, transparent 1px),
        linear-gradient(to bottom, color-mix(in srgb, var(--text) 8%, transparent) 1px, transparent 1px);
    background-size: 12px 12px;
}
.wp-preview-dawn .wallpaper-chip-preview {
    background-image:
        radial-gradient(60px 40px at 20% 20%,  rgba(255, 122, 89, 0.55), transparent 70%),
        radial-gradient(70px 50px at 100% 100%, rgba(109, 74, 255, 0.50), transparent 70%);
}
.wp-preview-midnight .wallpaper-chip-preview {
    background-color: #0a0d1f;
    background-image:
        radial-gradient(60px 40px at 100% 0%,  rgba(109, 74, 255, 0.55), transparent 70%),
        radial-gradient(70px 50px at 0% 100%, rgba(14, 165, 233, 0.45), transparent 70%);
}
.wallpaper-chip-label {
    font-size: 11px;
    text-align: center;
    color: var(--text-soft);
}
.wallpaper-chip.active .wallpaper-chip-label { color: var(--primary); font-weight: 600; }

/* Accent-color picker — same chip grid as wallpapers; swatch shows the
 * primary gradient so the user reads "mine-bubble будет вот таким". */
.accent-chip {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 4px;
    padding: 6px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.12s ease, box-shadow 0.12s ease;
}
.accent-chip:hover { transform: translateY(-1px); border-color: var(--border-strong); }
.accent-chip.active {
    border-color: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 35%, transparent);
}
.accent-chip-swatch {
    display: block;
    height: 44px;
    border-radius: 8px;
}
.accent-chip-label {
    font-size: 11px;
    text-align: center;
    color: var(--text-soft);
}
.accent-chip.active .accent-chip-label { color: var(--primary); font-weight: 600; }

/* Density picker — two flat chips. Active gets the primary accent fill. */
.density-picker {
    display: flex;
    gap: 8px;
    margin: 4px 0 8px;
}
.density-chip {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text);
    border-radius: var(--radius-md);
    cursor: pointer;
    font-size: 13px;
    transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}
.density-chip:hover { border-color: var(--border-strong); }
.density-chip.active {
    background: color-mix(in srgb, var(--primary) 18%, var(--bg-elev));
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

/* Konami-code confetti layer — fixed full-screen overlay, emoji glyphs
   fall from the top with random x, delay, rotation and duration. */
.confetti-layer {
    position: fixed;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    z-index: 9999;
}
.confetti {
    position: absolute;
    top: -40px;
    left: var(--x);
    font-size: 24px;
    animation: confettiFall var(--dur) cubic-bezier(.3,.7,.4,1) var(--delay) forwards;
    will-change: transform;
}
@keyframes confettiFall {
    0%   { transform: translateY(0) rotate(0); opacity: 0; }
    10%  { opacity: 1; }
    100% { transform: translateY(105vh) rotate(var(--rot)); opacity: 0.9; }
}

.sessions-list, .admin-users-list { list-style: none; margin: 0; padding: 0; max-height: 360px; overflow: auto; min-width: 380px; }
.sessions-list li, .admin-users-list li {
    padding: 10px 12px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.sessions-list li:last-child, .admin-users-list li:last-child { border-bottom: 0; }
.session-row { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.admin-users-list .badge.banned { background: var(--danger); }

/* Attachments */
.attachments { margin-top: 6px; display: flex; flex-direction: column; gap: 4px; }
.attach-img { max-width: 280px; max-height: 220px; border-radius: var(--radius-md); display: block; }
.attach-link {
    background: var(--bg-hover);
    color: var(--primary);
    font-size: 12px;
    padding: 4px 10px;
    border-radius: var(--radius-sm);
    text-decoration: none;
}
#messages-list li.mine .attach-link { background: rgba(255,255,255,.2); color: #fff; }
.attach-chip {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    background: var(--primary-soft);
    border-radius: var(--radius-pill);
    padding: 3px 10px;
    font-size: 12px;
    color: var(--primary);
}

/* ---------- Avatars ---------- */
.avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 34px; height: 34px;
    border-radius: 50%;
    color: #fff;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.03em;
    flex-shrink: 0;
    box-shadow: inset 0 0 0 2px rgba(255,255,255,.12);
    text-shadow: 0 1px 1px rgba(0,0,0,.15);
}
#chats-list .avatar { width: 38px; height: 38px; font-size: 13px; }
/* Photo avatar: <img> fills the round span, keeping the coloured
   background underneath as a placeholder / fallback. The span itself
   already handles online dot + box-shadow, so the image just needs to
   cover the circle cleanly. */
.avatar.avatar-img { overflow: hidden; }
.avatar.avatar-img img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    border-radius: inherit;
}
.sender-row { display: flex; gap: 6px; align-items: center; margin-bottom: 3px; }
.sender-row .avatar { width: 20px; height: 20px; font-size: 10px; box-shadow: none; text-shadow: none; }

/* ---------- Date separators ---------- */
#messages-list li.date-sep {
    align-self: center;
    background: transparent;
    color: var(--text-muted);
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 4px 12px;
    margin: 10px 0 4px;
    max-width: none;
    animation: none;
    box-shadow: none;
    border-radius: 0;
    font-weight: 600;
}
#messages-list li.date-sep::before, #messages-list li.date-sep::after {
    content: '';
    display: inline-block;
    width: 40px;
    height: 1px;
    background: var(--border);
    vertical-align: middle;
    margin: 0 10px;
}

/* ---------- Sticky date pill ----------
   Floats above #messages-list while scrolling. Reflects the top-most
   visible message's date so the user always sees "where" they are in the
   timeline. Hidden at the top of the list and when no chat is open. */
.sticky-date {
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 4;
    padding: 4px 12px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    font-weight: 600;
    color: var(--text-muted);
    background: color-mix(in srgb, var(--bg-elev) 92%, transparent);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    backdrop-filter: blur(6px);
    pointer-events: none;
    animation: stickyDateIn 0.15s ease-out;
}
@keyframes stickyDateIn { from { opacity: 0; transform: translate(-50%, -4px); } to { opacity: 1; transform: translate(-50%, 0); } }
.sticky-date[hidden] { display: none !important; }

/* ---------- Jump-to-first-unread chip ----------
   Pill at the top of the messages area that appears when the user has
   scrolled past the "Новые сообщения" separator. Click jumps back. */
.jump-unread {
    position: absolute;
    top: 40px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5;
    padding: 5px 14px;
    font-size: 12px;
    font-weight: 600;
    color: #fff;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-pill);
    cursor: pointer;
    box-shadow: var(--shadow-md);
    animation: stickyDateIn 0.18s ease-out;
    transition: transform var(--dur) var(--ease), filter var(--dur) var(--ease);
}
.jump-unread:hover { transform: translate(-50%, -2px); filter: brightness(1.05); }
.jump-unread[hidden] { display: none !important; }

/* ---------- @me mention highlight ----------
   A message that @-tags the current user gets a soft tinted left border
   and background so it jumps out in a busy chat. */
#messages-list li.mentions-me {
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    border-left: 3px solid var(--primary);
    padding-left: 10px;
    border-radius: 4px;
}

/* "Закрепил X" line inside the pins panel head. */
.pin-by { margin-left: auto; font-size: 11px; }

/* ---------- Quick chat switcher (Ctrl/Cmd+K) ---------- */
.quick-switch::backdrop { background: rgba(0, 0, 0, 0.32); backdrop-filter: blur(4px); }
.quick-switch-card {
    min-width: 440px;
    max-width: 560px;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 10px;
}
#quick-switch-input {
    font-size: 15px;
    padding: 10px 14px;
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    outline: none;
}
#quick-switch-input:focus { border-color: var(--primary); }
#quick-switch-list {
    list-style: none;
    margin: 0;
    padding: 0;
    max-height: 320px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 2px;
}
.quick-switch-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--dur) var(--ease);
}
.quick-switch-row:hover,
.quick-switch-row.active {
    background: color-mix(in srgb, var(--primary) 14%, transparent);
}
.quick-switch-title { flex: 1; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quick-switch-unread {
    min-width: 20px;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--primary);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
    line-height: 18px;
    text-align: center;
}
.quick-switch-hint { font-size: 11px; text-align: center; }

/* ---------- Message info popover ---------- */
.msg-info-pop {
    position: fixed;
    z-index: 80;
    padding: 8px 12px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-md);
    font-size: 12px;
    min-width: 220px;
    animation: stickyDateIn 0.12s ease-out;
}
.msg-info-row { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.msg-info-k { color: var(--text-muted); }
.msg-info-v { font-family: var(--font-mono, ui-monospace, monospace); }

/* Make the meta row look clickable so users discover the info popover. */
#messages-list li .meta { cursor: pointer; }
#messages-list li .meta:hover { color: var(--text); }

/* ---------- Reply-count chip ----------
   "↩ N" appears under a message when someone has replied to it. Clicking
   jumps to the first such reply. */
.reply-count {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    margin-top: 4px;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--primary);
    background: color-mix(in srgb, var(--primary) 10%, transparent);
    border: 1px solid color-mix(in srgb, var(--primary) 28%, transparent);
    border-radius: var(--radius-pill);
    cursor: pointer;
    align-self: flex-start;
    transition: background var(--dur) var(--ease), transform var(--dur) var(--ease);
}
.reply-count:hover {
    background: color-mix(in srgb, var(--primary) 20%, transparent);
    transform: translateY(-1px);
}

/* ---------- Admin ---------- */
.admin-card { min-width: 560px; max-width: 700px; padding: 24px; }
.admin-tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 14px; }
.admin-tabs .tab {
    background: transparent;
    color: var(--text-soft);
    padding: 8px 14px;
    border-radius: var(--radius-md) var(--radius-md) 0 0;
    font-weight: 500;
    border: 0;
}
.admin-tabs .tab:hover { background: var(--bg-hover); color: var(--text); }
.admin-tabs .tab.active { background: var(--primary-soft); color: var(--primary); }
.admin-audit-list { list-style: none; margin: 0; padding: 0; max-height: 380px; overflow: auto; }
.admin-audit-list li { padding: 8px 12px; border-bottom: 1px solid var(--border); }
.admin-audit-list li.muted { color: var(--text-muted); font-style: italic; border: 0; }
.admin-audit-list .small { font-size: 11px; word-break: break-all; color: var(--text-soft); }

/* ============================================================
   THEME TOGGLE — dual icon cross-fade + rotate.
   Sun is the "offered action" in light mode (click to go dark);
   moon is the offered action in dark. Exactly one visible at a time.
   ============================================================ */
.theme-toggle { position: relative; }
.theme-toggle svg {
    position: absolute;
    inset: 7px;
    width: 18px; height: 18px;
    transition: opacity 260ms var(--ease), transform 360ms var(--ease);
}
.theme-toggle .ico-sun  { opacity: 0; transform: rotate(-90deg) scale(.6); }
.theme-toggle .ico-moon { opacity: 1; transform: rotate(0)      scale(1); }
body.dark .theme-toggle .ico-sun  { opacity: 1; transform: rotate(0)      scale(1); }
body.dark .theme-toggle .ico-moon { opacity: 0; transform: rotate(90deg)  scale(.6); }

/* Chime toggle — same crossfade pattern as theme-toggle. Bell visible
   when sound is on, bell-off visible when muted. body.chime-muted drives
   the swap. */
.chime-toggle { position: relative; }
.chime-toggle svg {
    position: absolute;
    inset: 7px;
    width: 18px; height: 18px;
    transition: opacity 220ms var(--ease), transform 320ms var(--ease);
}
.chime-toggle .ico-bell      { opacity: 1; transform: scale(1); }
.chime-toggle .ico-bell-off  { opacity: 0; transform: scale(.6); }
body.chime-muted .chime-toggle .ico-bell      { opacity: 0; transform: scale(.6); }
body.chime-muted .chime-toggle .ico-bell-off  { opacity: 1; transform: scale(1); }
body.chime-muted .chime-toggle { color: var(--muted); }

/* Chat-header mute toggle reuses the same bell/bell-off crossfade. The
   "muted" modifier class is flipped via JS based on per-chat state. */
.chat-mute { position: relative; }
.chat-mute svg {
    position: absolute;
    inset: 7px;
    width: 18px; height: 18px;
    transition: opacity 220ms var(--ease), transform 320ms var(--ease);
}
.chat-mute .ico-bell      { opacity: 1; transform: scale(1); }
.chat-mute .ico-bell-off  { opacity: 0; transform: scale(.6); }
.chat-mute.muted .ico-bell      { opacity: 0; transform: scale(.6); }
.chat-mute.muted .ico-bell-off  { opacity: 1; transform: scale(1); }
.chat-mute.muted { color: var(--muted); }

/* Density toggle — active (compact) state gets a primary-tinted fill so
   the user can see at a glance which density is in effect. */
.density-toggle {
    font-size: 14px;
    line-height: 1;
    font-weight: 700;
}
.density-toggle[aria-pressed="true"] {
    background: var(--primary);
    color: #fff;
}

/* Accent-colour cycler — circular swatch reflecting the current palette.
   Clicking rotates through six curated hues. */
.accent-toggle { position: relative; }
.accent-dot {
    display: inline-block;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--primary);
    border: 2px solid var(--bg-elev);
    box-shadow: 0 0 0 1px var(--border);
    transition: background 0.2s ease, transform 0.2s ease;
}
.accent-toggle:hover .accent-dot { transform: scale(1.15); }

/* Swipe-to-reply — a reply-arrow emerges from the leading edge while the
   user drags right. Armed state (past the threshold) emphasises the
   arrow so the user knows the gesture will commit on release. */
#messages-list li[data-msg-id] { position: relative; }
#messages-list li[data-msg-id]::before {
    content: '↩';
    position: absolute;
    left: -30px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--primary);
    font-size: 18px;
    opacity: 0;
    transition: opacity 0.1s linear, transform 0.12s ease;
    pointer-events: none;
}
#messages-list li[data-msg-id][style*="translateX"]::before {
    opacity: calc(var(--swipe-op, 0.6));
}
#messages-list li.swipe-armed::before {
    opacity: 1;
    transform: translateY(-50%) scale(1.25);
}

/* Compact mode — tighter padding on message bubbles and chat rows so more
   content fits on screen. Only shrinks vertical metrics; fonts unchanged
   to keep readability. */
body.compact #messages-list { gap: 3px; padding: 12px 16px; }
body.compact #messages-list li { padding: 6px 12px; margin-top: 1px; }
body.compact #messages-list li.date-sep { margin: 6px 0 2px; }
body.compact #chats-list li { padding: 8px 12px; }
body.compact .chat-preview { margin-top: 1px; }

/* ============================================================
   NEW-GROUP button in sidebar + group creation dialog.
   ============================================================ */
.new-group-btn {
    margin: 0 12px 12px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 8px 14px;
}
.new-group-btn .ico-leading { width: 16px; height: 16px; display: inline-block; }

/* Sidebar filter row — compact search that narrows the chat list in place */
.chat-filter-row {
    padding: 0 12px 8px;
    border-bottom: 1px solid var(--border);
    margin-bottom: 4px;
    display: flex;
    gap: 6px;
    align-items: center;
}
.chat-filter-row input {
    flex: 1;
    min-width: 0;
    padding: 7px 12px;
    font-size: 13px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    background: var(--bg);
}
.chat-filter-row input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-soft);
}
.unread-only-btn {
    flex-shrink: 0;
    width: 30px;
    height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    font-size: 11px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.unread-only-btn:hover { border-color: var(--primary); color: var(--primary); }
.unread-only-btn[aria-pressed="true"] {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px var(--primary-soft);
}
/* Archive toggle reuses the pill styling of .unread-only-btn but is a
   separate selector so the two don't both light up at once and the
   archive-on state reads as "viewing archive" rather than a filter. */
.show-archived-btn {
    flex-shrink: 0;
    width: 30px; height: 30px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text-muted);
    font-size: 14px;
    cursor: pointer;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
}
.show-archived-btn:hover { border-color: var(--primary); color: var(--primary); }
.show-archived-btn[aria-pressed="true"] {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px var(--primary-soft);
}
.chat-empty-filter {
    list-style: none;
    padding: 14px 16px;
    color: var(--text-muted);
    font-size: 13px;
    text-align: center;
}

/* ---- Quick-reactions popover -------------------------------------- */
.reaction-popover {
    position: absolute;
    z-index: 100;
    display: flex;
    flex-direction: column;
    gap: 4px;
    align-items: stretch;
    padding: 6px;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    animation: popIn 160ms var(--ease);
}
.reaction-popover .emoji-btn {
    width: 32px;
    height: 32px;
    border: 0;
    background: transparent;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
    border-radius: 50%;
    transition: transform 120ms var(--ease), background 120ms var(--ease);
}
.reaction-popover .emoji-btn:hover {
    background: var(--primary-soft);
    transform: scale(1.2);
}
.reaction-popover .emoji-custom {
    width: 100%;
    padding: 4px 10px;
    border-radius: var(--radius-pill);
    border: 1px solid var(--border);
    font-size: 13px;
    background: var(--bg);
}
.reaction-popover .reaction-row {
    display: flex;
    gap: 4px;
    align-items: center;
}
.reaction-popover .reaction-recent {
    padding-bottom: 4px;
    border-bottom: 1px dashed var(--border);
    opacity: 0.95;
}
@keyframes popIn {
    from { opacity: 0; transform: translateY(-4px) scale(.9); }
    to   { opacity: 1; transform: none; }
}

/* ---- Toast (copy feedback etc.) ----------------------------------- */
.toast {
    position: fixed;
    right: 20px;
    bottom: 24px;
    padding: 10px 16px;
    background: var(--text);
    color: var(--bg);
    border-radius: var(--radius-pill);
    font-size: 13px;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    animation: toastIn 200ms var(--ease);
    opacity: .95;
    pointer-events: none;
    display: inline-flex;
    align-items: center;
    gap: 10px;
    max-width: min(92vw, 520px);
}
.toast.out { animation: toastOut 260ms var(--ease) forwards; }
.toast.toast-error {
    background: #dc2626;
    color: #fff;
    pointer-events: auto;
}
.toast-action {
    pointer-events: auto;
    background: rgba(255,255,255,0.18);
    color: inherit;
    border: 1px solid rgba(255,255,255,0.35);
    padding: 4px 12px;
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.15s;
}
.toast-action:hover { background: rgba(255,255,255,0.32); }
@keyframes toastIn  { from { opacity: 0; transform: translateY(10px); } to   { opacity: .95; transform: none; } }
@keyframes toastOut { from { opacity: .95; } to   { opacity: 0; transform: translateY(10px); } }

/* ---- Shortcuts dialog --------------------------------------------- */
.shortcuts-card { min-width: 380px; }
.shortcuts-list {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 10px 20px;
    margin: 12px 0;
}
.shortcuts-list dt {
    display: flex;
    gap: 4px;
    align-items: center;
    white-space: nowrap;
}
.shortcuts-list dd { margin: 0; color: var(--text-muted); font-size: 13px; }
kbd {
    display: inline-block;
    padding: 2px 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 11px;
    line-height: 1.4;
    background: var(--bg-elev-2, var(--bg-hover));
    border: 1px solid var(--border);
    border-radius: 4px;
    box-shadow: 0 1px 0 var(--border);
}

/* ---- Drag-and-drop overlay --------------------------------------- */
.drop-overlay {
    position: absolute;
    inset: 0;
    border: 3px dashed var(--primary);
    border-radius: var(--radius-lg);
    background: var(--primary-soft);
    color: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity 120ms var(--ease);
    z-index: 5;
    margin: 10px;
}
.drop-overlay.visible { opacity: 1; }

/* ---- @mention picker --------------------------------------------- */
.mention-picker {
    position: absolute;
    z-index: 150;
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: popIn 160ms var(--ease);
    max-height: 260px;
    overflow-y: auto;
}
.mention-picker[hidden] { display: none; }
.mention-item {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 8px 10px;
    cursor: pointer;
    transition: background 120ms var(--ease);
}
.mention-item:hover,
.mention-item.active { background: var(--primary-soft); }
.mention-item .avatar { width: 28px; height: 28px; font-size: 11px; }
.mention-name { font-weight: 500; font-size: 14px; }
.mention-handle { font-size: 12px; }

/* ---- @mention chips in message bodies --------------------------- */
/* Inline pill rendered by mentionizeInto() for every `@username` token
   that resolves to a known profile. Self-mentions get a warmer fill so
   the user can spot their name at a glance. */
#messages-list li .body .mention-chip {
    display: inline-block;
    padding: 0 6px;
    border-radius: 999px;
    background: var(--primary-soft);
    color: var(--primary);
    font-weight: 600;
    font-size: 0.95em;
    line-height: 1.5;
    cursor: pointer;
    transition: filter 120ms var(--ease);
}
#messages-list li .body .mention-chip:hover { filter: brightness(1.1); }
#messages-list li .body .mention-chip:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
#messages-list li .body .mention-chip.mention-self {
    background: #fde68a;
    color: #92400e;
}
body.dark #messages-list li .body .mention-chip.mention-self {
    background: #78350f;
    color: #fde68a;
}

/* ---- Consecutive-message grouping -------------------------------- */
/* When a message is a continuation of the same sender (< 5 min, not a
   reply) hide the sender-row and collapse the top gap so same-author
   streaks read as one block. Keep full sender-row on the first of a run. */
#messages-list li.grouped .sender-row { display: none; }
#messages-list li.grouped { margin-top: 2px; }
/* Smooth the bubble corners so the streak looks like a single shape. */
#messages-list li.grouped:not(.mine) { border-top-left-radius: 6px; }
#messages-list li.grouped.mine       { border-top-right-radius: 6px; }

/* ---- Markdown-lite in message bodies --------------------------- */
#messages-list li .body code {
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
    padding: 1px 6px;
    border-radius: 4px;
    background: var(--bg-hover);
    color: var(--text);
}
#messages-list li.mine .body code {
    background: rgba(255, 255, 255, .16);
    color: #fff;
}
#messages-list li .body strong { font-weight: 700; }
#messages-list li .body em     { font-style: italic; }
#messages-list li .body .code-block {
    position: relative;
    margin: 6px 0 2px;
    padding: 10px 12px;
    background: var(--bg-hover);
    border: 1px solid var(--border);
    border-radius: 6px;
    overflow-x: auto;
    max-width: 100%;
}
#messages-list li .body .code-block .code-copy {
    position: absolute;
    top: 4px;
    right: 4px;
    border: 1px solid var(--border);
    background: var(--bg-elev);
    color: var(--text-muted);
    width: 24px;
    height: 24px;
    padding: 0;
    border-radius: 4px;
    font-size: 13px;
    line-height: 22px;
    cursor: pointer;
    opacity: 0;
    transition: opacity var(--dur) var(--ease), color var(--dur) var(--ease);
}
#messages-list li .body .code-block:hover .code-copy,
#messages-list li .body .code-block .code-copy:focus-visible { opacity: 1; }
#messages-list li .body .code-block .code-copy:hover { color: var(--primary); }
#messages-list li .body .code-block code {
    display: block;
    padding: 0;
    background: transparent;
    color: var(--text);
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-size: 12.5px;
    line-height: 1.5;
    white-space: pre;
}
#messages-list li.mine .body .code-block {
    background: rgba(255, 255, 255, .12);
    border-color: rgba(255, 255, 255, .18);
}
#messages-list li.mine .body .code-block code { color: #fff; }

/* Sender name in group chats picks up a per-user tint via inline style;
   nothing else to add here but we keep the avatar hover state subtle. */
#messages-list li .sender-row .avatar { transition: transform var(--dur) var(--ease); }
#messages-list li .sender-row .avatar:hover { transform: scale(1.08); }

/* ---- Image lightbox ------------------------------------------- */
.lightbox {
    position: fixed;
    inset: 0;
    background: rgba(10, 10, 15, .82);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 500;
    cursor: zoom-out;
    opacity: 0;
    transition: opacity 180ms var(--ease);
    backdrop-filter: blur(6px);
}
.lightbox.open { opacity: 1; }
.lightbox img {
    max-width: 92vw;
    max-height: 92vh;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    cursor: default;
    animation: lightboxIn 240ms var(--ease);
}
.lightbox-close {
    position: absolute;
    top: 20px;
    right: 24px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 0;
    background: rgba(255, 255, 255, .12);
    color: #fff;
    font-size: 24px;
    cursor: pointer;
    transition: background 120ms var(--ease), transform 120ms var(--ease);
}
.lightbox-close:hover { background: rgba(255, 255, 255, .22); transform: scale(1.08); }
@keyframes lightboxIn {
    from { opacity: 0; transform: scale(.92); }
    to   { opacity: 1; transform: none; }
}
#messages-list .attach-img { cursor: zoom-in; }

.group-search-results {
    list-style: none;
    margin: 4px 0 8px;
    padding: 0;
    max-height: 180px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg);
}
.group-search-results:empty { display: none; }
.group-search-results li {
    padding: 8px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    display: flex;
    gap: 8px;
    align-items: center;
    transition: background var(--dur) var(--ease);
}
.group-search-results li:last-child { border-bottom: 0; }
.group-search-results li:hover { background: var(--primary-soft); }

.group-members {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
    min-height: 36px;
    margin-top: 6px;
}
.group-member-chip {
    display: inline-flex;
    gap: 6px;
    align-items: center;
    padding: 4px 4px 4px 10px;
    background: var(--primary-soft);
    color: var(--primary);
    border-radius: var(--radius-pill);
    font-size: 12px;
    font-weight: 500;
    animation: chipIn 180ms var(--ease) both;
}
.group-member-chip button {
    width: 20px; height: 20px;
    padding: 0;
    background: rgba(255,255,255,.6);
    color: var(--primary);
    border-radius: 50%;
    font-size: 11px;
    line-height: 1;
}
body.dark .group-member-chip button { background: rgba(0,0,0,.2); }
@keyframes chipIn {
    from { opacity: 0; transform: scale(.6); }
    to   { opacity: 1; transform: none; }
}

/* Группа: блок «Участники» внутри диалога редактирования профиля.
 * Рендерится поверх существующего .avatar (включая .online dot) — никаких
 * новых индикаторов; клик по чипу открывает peek-профиль. */
.group-edit-members-block {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 6px;
}
.group-edit-members-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 13px;
}
.group-edit-members-title { font-weight: 600; }
.group-edit-members {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    max-height: 220px;
    overflow-y: auto;
    padding: 4px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-subtle);
}
.group-edit-member {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px 4px 4px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    font-size: 12px;
    cursor: pointer;
    transition: background 120ms var(--ease), border-color 120ms var(--ease);
}
.group-edit-member:hover { background: var(--primary-soft); border-color: var(--primary); }
.group-edit-member.is-online { border-color: var(--online, #2e9a4a); }
.group-edit-member .avatar { width: 24px; height: 24px; font-size: 10px; }
.group-edit-member-name {
    max-width: 160px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* ============================================================
   DIALOG entrance animation + chat-list stagger.
   ============================================================ */
dialog[open] {
    animation: dialogIn 240ms var(--ease);
}
dialog[open]::backdrop {
    animation: backdropIn 240ms var(--ease);
}
@keyframes dialogIn {
    from { opacity: 0; transform: translateY(10px) scale(.96); }
    to   { opacity: 1; transform: none; }
}
@keyframes backdropIn {
    from { opacity: 0; }
    to   { opacity: 1; }
}

#chats-list li {
    animation: chatRowIn 220ms var(--ease) both;
}
@keyframes chatRowIn {
    from { opacity: 0; transform: translateX(-8px); }
    to   { opacity: 1; transform: none; }
}

/* Unread badge pulse — subtle attention draw without being annoying. */
.badge {
    animation: badgePulse 1.6s var(--ease) infinite;
}
.badge.banned { animation: none; }
@keyframes badgePulse {
    0%, 100% { box-shadow: 0 0 0 0 rgba(79, 70, 229, 0.4); }
    50%      { box-shadow: 0 0 0 6px rgba(79, 70, 229, 0); }
}

/* Send button pressed animation — a little nudge on click. */
#send-form button[type=submit]:active:not(:disabled) {
    animation: sendPop 260ms var(--ease);
}
@keyframes sendPop {
    0%   { transform: translateX(0) rotate(0); }
    40%  { transform: translateX(3px) rotate(-4deg); }
    100% { transform: translateX(0) rotate(0); }
}

/* ---- Voice messages ---------------------------------------------- */
.record-btn {
    position: relative;
    background: transparent;
    border: 1px solid var(--border);
    border-radius: var(--radius-pill);
    width: 36px; height: 36px;
    color: var(--text);
    cursor: pointer;
    transition: color 120ms var(--ease), border-color 120ms var(--ease),
                background 120ms var(--ease);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    user-select: none;
    touch-action: none;
}
.record-btn svg { width: 18px; height: 18px; }
.record-btn:hover { background: var(--bg-hover); }
.record-btn.recording {
    color: #fff;
    background: #ef4444;
    border-color: #ef4444;
}
.record-btn .record-dot {
    display: none;
    position: absolute;
    top: 4px; right: 4px;
    width: 8px; height: 8px;
    background: #fca5a5;
    border-radius: 50%;
    animation: recordPulse 1.2s ease-in-out infinite;
}
.record-btn.recording .record-dot { display: block; }
@keyframes recordPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50%      { opacity: 0.4; transform: scale(1.25); }
}
.record-overlay {
    position: absolute;
    left: 12px; right: 12px;
    bottom: 68px;
    z-index: 100;
    animation: popIn 160ms var(--ease);
}
.record-overlay[hidden] { display: none; }
.record-overlay-inner {
    background: #ef4444;
    color: #fff;
    border-radius: var(--radius-md);
    padding: 10px 14px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-lg);
}
.record-pulse {
    width: 12px; height: 12px;
    border-radius: 50%;
    background: #fff;
    animation: recordPulse 1s ease-in-out infinite;
    flex-shrink: 0;
}
#record-timer {
    font-family: var(--font-mono, ui-monospace, monospace);
    font-size: 15px;
    font-weight: 600;
    flex: 1;
}
.record-stop, .record-cancel {
    background: rgba(255, 255, 255, 0.2);
    border: 1px solid rgba(255, 255, 255, 0.35);
    color: #fff;
    padding: 6px 12px;
    border-radius: var(--radius-pill);
    font-size: 13px;
    cursor: pointer;
    transition: background 120ms var(--ease);
}
.record-stop:hover, .record-cancel:hover { background: rgba(255,255,255,0.35); }

/* Audio attachments use the native player at a constrained size. */
#messages-list li .attach-audio {
    display: block;
    max-width: 320px;
    height: 36px;
    margin-top: 4px;
}
#messages-list li.mine .attach-audio {
    filter: brightness(1.1);
}

/* Видео-вложения: inline-плеер в размерах изображения-превью. controls:
 * стандартный браузерный, контролируется по месту без всплывающих
 * лайтбоксов (как audio). background — чёрный, чтобы до загрузки poster'а
 * место под видео не мелькало серым. */
#messages-list li .attach-video {
    display: block;
    max-width: 320px;
    max-height: 240px;
    border-radius: var(--radius-md);
    margin-top: 4px;
    background: #000;
}

/* Keyboard-focused message outline (j/k navigation). */
#messages-list li.focused {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

/* ---- Chat stats dialog ------------------------------------------- */
.stats-card { min-width: 380px; max-width: 520px; }
.stats-summary {
    display: grid;
    grid-template-columns: max-content 1fr;
    gap: 4px 14px;
    margin: 10px 0;
    font-size: 13px;
}
.stats-summary dt { color: var(--text-muted); }
.stats-summary dd { margin: 0; font-weight: 600; }
.stats-att-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 2px 0 10px;
}
.stats-att-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 9px;
    border-radius: 999px;
    background: var(--bg-elev-2, var(--bg-elev));
    border: 1px solid var(--border);
    font-size: 12px;
    color: var(--text);
}
.stats-section { margin: 14px 0 6px; font-size: 14px; }
.stats-react-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin: 0 0 8px;
}
.stats-react-chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 999px;
    background: var(--bg-elev-2, var(--bg-elev));
    border: 1px solid var(--border);
    font-size: 13px;
}
.stats-hours {
    display: grid;
    grid-template-columns: repeat(24, 1fr);
    gap: 2px;
    align-items: end;
    height: 80px;
    padding: 2px 0 0;
}
.stats-hour-col {
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
    align-items: center;
    gap: 2px;
    height: 100%;
}
.stats-hour-bar {
    width: 100%;
    background: linear-gradient(to top, var(--primary), color-mix(in srgb, var(--primary) 50%, transparent));
    border-radius: 2px 2px 0 0;
    min-height: 2px;
    transition: filter var(--dur) var(--ease);
}
.stats-hour-bar:hover { filter: brightness(1.15); }
.stats-hour-label { font-size: 9px; color: var(--text-muted); line-height: 1; height: 10px; }
.stats-users {
    list-style: none;
    margin: 0; padding: 0;
    max-height: 320px;
    overflow-y: auto;
}
.stats-user-row {
    display: flex;
    gap: 10px;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}
.stats-user-row:last-child { border-bottom: 0; }
.stats-user-info { flex: 1; min-width: 0; }
.stats-user-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    font-size: 13px;
    margin-bottom: 4px;
}
.stats-bar {
    height: 6px;
    background: var(--border);
    border-radius: 999px;
    overflow: hidden;
}
.stats-bar-fill {
    display: block;
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-strong, var(--primary)));
    transition: width 400ms var(--ease);
}

/* ---- Forward dialog ----------------------------------------------- */
.forward-card { min-width: 340px; max-width: 440px; }
.forward-card #forward-preview {
    background: var(--bg-elev);
    border-radius: var(--radius-sm);
    padding: 8px 10px;
    margin: 8px 0;
    font-size: 13px;
    white-space: pre-wrap;
    word-break: break-word;
}
.forward-card #forward-filter {
    width: 100%;
    margin-bottom: 8px;
}
.forward-chat-list {
    list-style: none;
    margin: 0; padding: 0;
    max-height: 320px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.forward-chat-item {
    padding: 10px 12px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 120ms var(--ease);
}
.forward-chat-item:last-child { border-bottom: 0; }
.forward-chat-item:hover { background: var(--primary-soft); }
.forward-empty { padding: 16px; text-align: center; }

/* ---- Saved messages dialog --------------------------------------- */
.saved-card { min-width: 380px; max-width: 520px; }
.saved-list {
    list-style: none;
    margin: 10px 0;
    padding: 0;
    max-height: 420px;
    overflow-y: auto;
}
.saved-item {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    padding: 10px 12px;
    margin-bottom: 8px;
    animation: popIn 180ms var(--ease);
}
.saved-head {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: baseline;
    margin-bottom: 4px;
}
.saved-time { font-size: 11px; }
.saved-body {
    white-space: pre-wrap;
    word-break: break-word;
    font-size: 14px;
    line-height: 1.45;
    margin-bottom: 8px;
}
.saved-actions { display: flex; gap: 8px; }
.saved-jump { padding: 4px 10px; font-size: 12px; }
.saved-drop {
    background: transparent;
    border: 1px solid var(--border);
    border-radius: 999px;
    width: 26px; height: 26px;
    color: var(--muted);
    cursor: pointer;
    transition: color 120ms var(--ease), border-color 120ms var(--ease);
}
.saved-drop:hover { color: var(--danger, #ef4444); border-color: var(--danger, #ef4444); }
.saved-empty { padding: 24px; text-align: center; }

/* ---------- Composer char counter ---------- */
.composer-count {
    font-size: 11px;
    color: var(--muted);
    padding: 0 6px;
    align-self: center;
    font-variant-numeric: tabular-nums;
    transition: color 120ms var(--ease);
    pointer-events: none;
}
.composer-count-warn { color: #f59e0b; }
.composer-count-full { color: var(--danger, #ef4444); font-weight: 600; }

/* ---------- Chat alias icon ---------- */
.chat-alias-icon {
    font-size: 11px;
    color: var(--accent);
    margin-left: 4px;
    opacity: 0.7;
}

/* ---------- Slash-command hints ---------- */
.slash-hints {
    margin: 0 10px 6px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-elev);
    overflow: hidden;
    box-shadow: 0 4px 12px rgba(0,0,0,0.08);
    max-height: 200px;
    overflow-y: auto;
}
.slash-hint {
    display: flex;
    gap: 12px;
    padding: 6px 10px;
    cursor: pointer;
    align-items: baseline;
    font-size: 12px;
    transition: background 80ms var(--ease);
}
.slash-hint:hover { background: var(--bg-hover); }
.slash-hint-cmd { font-family: ui-monospace, monospace; color: var(--accent); }
.slash-hint-desc { font-size: 11px; }

/* ---------- Recent-emoji strip above composer ---------- */
.recent-emoji-bar {
    display: flex;
    gap: 2px;
    padding: 4px 10px 2px;
    overflow-x: auto;
    scrollbar-width: none;
}
.recent-emoji-bar::-webkit-scrollbar { display: none; }
.recent-emoji-cell {
    flex: 0 0 auto;
    width: 28px; height: 28px;
    border: 0; background: transparent;
    font-size: 18px; line-height: 1;
    cursor: pointer;
    border-radius: 6px;
    transition: background 120ms var(--ease), transform 120ms var(--ease);
}
.recent-emoji-cell:hover { background: var(--bg-hover); transform: scale(1.1); }

/* ---------- Chat header scroll progress ---------- */
.chat-progress {
    height: 2px;
    width: 100%;
    background: transparent;
    overflow: hidden;
}
.chat-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, var(--accent-soft), var(--accent));
    transition: width 120ms var(--ease);
}

/* ---------- Spoiler text (||text||) ---------- */
.spoiler {
    background: var(--text);
    color: transparent;
    border-radius: 3px;
    padding: 0 2px;
    cursor: pointer;
    transition: background 180ms var(--ease), color 180ms var(--ease);
    user-select: none;
}
.spoiler:hover { background: var(--muted); }
.spoiler.revealed {
    background: transparent;
    color: inherit;
    user-select: text;
}
.spoiler.revealed::selection { background: var(--accent-soft); }

/* ---------- Jumbo emoji-only messages ---------- */
.body.jumbo-emoji {
    font-size: 2.5em;
    line-height: 1.1;
    padding: 4px 0;
}

/* ---------- DND toggle ---------- */
#btn-dnd.active { color: var(--accent); background: var(--accent-soft); }

/* ---------- Quick-switch command rows ---------- */
.quick-switch-cmd-icon {
    width: 32px; height: 32px; border-radius: 8px;
    background: var(--bg-hover); display: flex;
    align-items: center; justify-content: center;
    font-size: 16px;
}
.quick-switch-cmd-hint {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-left: auto;
}

/* ---------- Font-size toggle ---------- */
#btn-fontsize { font-weight: 600; font-size: 12px; letter-spacing: 0.02em; }
body[data-fontsize="small"] #btn-fontsize { font-size: 11px; }
body[data-fontsize="large"] #btn-fontsize { font-size: 14px; }

/* ---------- Focus mode (hides sidebar) ---------- */
body.focus-mode #chat-view aside {
    width: 0 !important;
    min-width: 0 !important;
    overflow: hidden;
    border-right: 0;
    transition: width 200ms var(--ease);
}
body.focus-mode #sidebar-resizer { display: none; }

/* ---------- Empty-filter reset button ---------- */
.chat-empty-filter {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    padding: 20px 12px;
    text-align: center;
}
.chat-empty-clear {
    padding: 4px 12px;
    font-size: 12px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    cursor: pointer;
    transition: color 120ms var(--ease), border-color 120ms var(--ease);
}
.chat-empty-clear:hover { color: var(--accent); border-color: var(--accent); }

/* ---------- Clickable chat-time chip ---------- */
.chat-time { cursor: pointer; }
.chat-time[data-abs="1"] { color: var(--accent); }

/* ---------- Sidebar chat-kind tabs ---------- */
.chat-kind-tabs {
    display: flex;
    gap: 4px;
    padding: 4px 10px 8px;
    border-bottom: 1px solid var(--border);
}
.chat-kind-tab {
    flex: 1;
    padding: 6px 8px;
    font-size: 12px;
    background: transparent;
    border: 1px solid transparent;
    color: var(--muted);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: color 120ms var(--ease), background 120ms var(--ease), border-color 120ms var(--ease);
}
.chat-kind-tab:hover { color: var(--text); background: var(--bg-hover); }
.chat-kind-tab.active {
    color: var(--accent);
    background: var(--accent-soft);
    border-color: var(--accent-soft);
    font-weight: 600;
}

/* ---------- Sidebar stats strip ---------- */
.sidebar-stats {
    padding: 6px 16px 2px;
    font-size: 11px;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
    font-variant-numeric: tabular-nums;
    display: flex;
    align-items: center;
    gap: 8px;
}
.sidebar-stats-text { flex: 1; min-width: 0;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
/* Inline action pill — only visible when there's unread to clear.
   Accent-tinted so it stands out against the muted stats row without
   shouting; compact so the row height doesn't jump. */
.sidebar-stats-action {
    flex-shrink: 0;
    padding: 2px 10px;
    font-size: 10px;
    font-weight: 600;
    letter-spacing: 0.02em;
    text-transform: none;
    border: 1px solid var(--primary);
    background: transparent;
    color: var(--primary);
    border-radius: var(--radius-pill);
    cursor: pointer;
    transition: background 0.15s, color 0.15s;
}
.sidebar-stats-action:hover {
    background: var(--primary);
    color: #fff;
}

/* ---------- Offline state ---------- */
body.net-offline #conn-dot::after {
    content: '';
    position: absolute;
    inset: -3px;
    border: 2px dashed #dc2626;
    border-radius: 50%;
    animation: offline-pulse 1.6s ease-in-out infinite;
}
body.net-offline .sidebar-clock::after {
    content: ' · офлайн';
    color: #dc2626;
    font-weight: 600;
}
@keyframes offline-pulse {
    0%, 100% { opacity: 0.5; transform: scale(1); }
    50%      { opacity: 1;   transform: scale(1.2); }
}

/* ---------- Sidebar live clock ---------- */
.sidebar-clock {
    font-size: 11px;
    color: var(--muted);
    padding: 2px 12px 6px;
    letter-spacing: 0.3px;
    font-variant-numeric: tabular-nums;
    opacity: 0.7;
    user-select: none;
}
.sidebar-clock:empty { display: none; }

/* ---------- DND chip in chat header ---------- */
.dnd-chip {
    display: none;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 8px;
    border-radius: 999px;
    background: rgba(234, 179, 8, 0.15);
    color: #b45309;
    border: 1px solid rgba(234, 179, 8, 0.4);
    letter-spacing: 0.3px;
    margin-left: 8px;
}
body.dnd-on #dnd-chip { display: inline-flex; align-items: center; }
body.dark .dnd-chip { color: #fbbf24; background: rgba(234, 179, 8, 0.12); }

/* ---------- Blockquote ---------- */
.msg-quote {
    margin: 4px 0;
    padding: 2px 10px;
    border-left: 3px solid var(--accent);
    color: var(--muted);
    background: var(--bg-hover, rgba(127,127,127,0.08));
    border-radius: 0 6px 6px 0;
    white-space: pre-wrap;
}
.msg-quote:first-child { margin-top: 0; }
.msg-quote:last-child { margin-bottom: 0; }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
    #chat-view { flex-direction: column; }
    #chat-view aside { width: 100%; max-height: 45vh; border-right: 0; border-bottom: 1px solid var(--border); }
    #chat-view main { flex: 1; }
    #messages-list li { max-width: 85%; }
    .card, .profile-form, .admin-card, .sessions-list, .admin-users-list { min-width: 0 !important; }
    dialog { width: 92vw; }
    #auth-view { width: 100%; padding: 16px; }
}

/* ---------- Reduced motion ---------- */
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { animation-duration: 0ms !important; transition-duration: 0ms !important; }
}

/* ============================================================
   AUTH v2 — модернизированная форма входа/регистрации
   ============================================================ */
#auth-view { width: 420px; }
#auth-view .auth-brand { text-align: center; margin-bottom: 18px; }
.auth-logo {
    width: 72px; height: 72px; margin: 0 auto 10px;
    display: grid; place-items: center;
    border-radius: 20px;
    background: linear-gradient(135deg, rgba(99,102,241,.15), rgba(14,165,233,.15));
    box-shadow: 0 10px 30px -10px rgba(99,102,241,.55), inset 0 1px 0 rgba(255,255,255,.35);
    animation: authLogoPulse 3.2s var(--ease) infinite;
}
@keyframes authLogoPulse {
    0%, 100% { transform: scale(1); box-shadow: 0 10px 30px -10px rgba(99,102,241,.55), inset 0 1px 0 rgba(255,255,255,.35); }
    50%      { transform: scale(1.04); box-shadow: 0 18px 44px -12px rgba(99,102,241,.75), inset 0 1px 0 rgba(255,255,255,.5); }
}

.auth-card {
    position: relative;
    padding: 22px 22px 18px;
    border-radius: 18px;
    background: var(--surface, #fff);
    box-shadow: 0 20px 50px -18px rgba(15, 23, 42, .25), 0 2px 8px -2px rgba(15,23,42,.08);
    border: 1px solid var(--border);
    overflow: hidden;
}
.auth-card::before {
    content: ''; position: absolute; inset: 0 0 auto 0; height: 4px;
    background: linear-gradient(90deg, #6366f1, #0ea5e9, #10b981);
    background-size: 200% 100%;
    animation: authAccent 8s linear infinite;
}
@keyframes authAccent { from { background-position: 0 0; } to { background-position: 200% 0; } }

.auth-tabs {
    position: relative;
    display: flex;
    background: var(--bg-soft, rgba(99,102,241,.06));
    border-radius: 12px;
    padding: 4px;
    margin-bottom: 18px;
}
.auth-tab {
    flex: 1; padding: 10px 14px;
    background: transparent; border: 0; border-radius: 9px;
    font-weight: 600; font-size: 14px;
    color: var(--text-muted); cursor: pointer;
    transition: color .18s var(--ease);
    position: relative; z-index: 2;
}
.auth-tab.is-active { color: var(--primary, #4f46e5); }
.auth-tabs-ink {
    position: absolute; top: 4px; bottom: 4px; left: 4px;
    width: calc(33.333% - 2.67px);
    background: #fff;
    border-radius: 9px;
    box-shadow: 0 2px 8px -2px rgba(15,23,42,.12);
    transition: transform .25s var(--ease);
    z-index: 1;
}
#auth-view[data-mode="login"]    .auth-tabs-ink { transform: translateX(0); }
#auth-view[data-mode="register"] .auth-tabs-ink { transform: translateX(100%); }
#auth-view[data-mode="phone"]    .auth-tabs-ink { transform: translateX(200%); }

/* Inline hint line under the phone-code field — shows "код отправлен" +
 * (in dev mode) the code itself so the user can finish signup without
 * an SMS gateway. The <code> span gets a monospace chip for readability. */
#phone-hint {
    margin: -6px 0 12px;
    padding: 8px 12px;
    background: color-mix(in srgb, var(--primary) 10%, var(--bg-elev));
    border: 1px solid color-mix(in srgb, var(--primary) 25%, transparent);
    border-radius: var(--radius-md);
    font-size: 13px;
    color: var(--text);
}
#phone-hint code {
    display: inline-block;
    padding: 2px 8px;
    margin-left: 4px;
    background: var(--bg);
    border-radius: 6px;
    font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
    font-weight: 700;
    letter-spacing: 0.1em;
    color: var(--primary);
}

.auth-field { display: block; margin-bottom: 14px; text-align: left; }
.auth-field-label {
    display: block;
    font-size: 12px; font-weight: 600;
    color: var(--text-muted);
    letter-spacing: .02em; text-transform: uppercase;
    margin-bottom: 6px;
}
.auth-input-wrap {
    position: relative; display: flex; align-items: center;
    background: var(--bg-soft, #f8fafc);
    border: 1.5px solid var(--border);
    border-radius: 11px;
    padding: 0 10px;
    transition: border-color .15s var(--ease), box-shadow .15s var(--ease), background .15s var(--ease);
}
.auth-input-wrap:focus-within {
    border-color: var(--primary, #4f46e5);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(99,102,241,.15);
}
.auth-ico { flex: none; color: var(--text-muted); margin-right: 8px; }
.auth-input-wrap:focus-within .auth-ico { color: var(--primary, #4f46e5); }
.auth-input-wrap input {
    flex: 1; border: 0; background: transparent; outline: none;
    padding: 12px 0; font-size: 15px; color: var(--text, #0f172a);
    min-width: 0;
}
.auth-input-wrap input::placeholder { color: var(--text-muted); opacity: .65; }
.auth-eye {
    flex: none; background: transparent; border: 0; padding: 4px;
    color: var(--text-muted); cursor: pointer; border-radius: 6px;
}
.auth-eye:hover { color: var(--primary, #4f46e5); background: rgba(99,102,241,.08); }

#auth-status {
    min-height: 0; max-height: 0; overflow: hidden;
    padding: 0 12px; margin: 0 0 0;
    border-radius: 10px; font-size: 13px; font-weight: 500;
    transition: max-height .22s var(--ease), padding .22s var(--ease), margin .22s var(--ease);
}
#auth-status.is-shown { max-height: 120px; padding: 10px 12px; margin-bottom: 12px; }
#auth-status.error { background: rgba(239,68,68,.1); color: #dc2626; border: 1px solid rgba(239,68,68,.3); }
#auth-status.ok { background: rgba(16,185,129,.1); color: #059669; border: 1px solid rgba(16,185,129,.3); }
#auth-status.muted { background: rgba(99,102,241,.08); color: var(--primary, #4f46e5); border: 1px solid rgba(99,102,241,.2); }

.auth-primary {
    width: 100%; padding: 13px 18px;
    border: 0; border-radius: 12px;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 55%, #0ea5e9 130%);
    color: #fff; font-weight: 700; font-size: 15px; letter-spacing: .02em;
    cursor: pointer; position: relative;
    box-shadow: 0 10px 22px -10px rgba(99,102,241,.85), inset 0 1px 0 rgba(255,255,255,.25);
    transition: transform .15s var(--ease), box-shadow .15s var(--ease), filter .15s var(--ease);
    display: flex; align-items: center; justify-content: center; gap: 10px;
}
.auth-primary:hover:not([disabled]) { transform: translateY(-1px); box-shadow: 0 14px 28px -10px rgba(99,102,241,.9), inset 0 1px 0 rgba(255,255,255,.3); filter: brightness(1.05); }
.auth-primary:active { transform: translateY(0); }
.auth-primary[disabled] { cursor: wait; opacity: .85; }
.auth-primary.is-loading .auth-primary-label { opacity: .35; }
.auth-primary.is-loading .auth-spinner { opacity: 1; }
.auth-spinner {
    position: absolute;
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid rgba(255,255,255,.35);
    border-top-color: #fff;
    opacity: 0; animation: authSpin .75s linear infinite;
}
@keyframes authSpin { to { transform: rotate(360deg); } }

.auth-divider {
    display: flex; align-items: center; gap: 10px;
    margin: 18px 0 14px;
    font-size: 12px; color: var(--text-muted);
    text-transform: uppercase; letter-spacing: .08em;
}
.auth-divider::before, .auth-divider::after {
    content: ''; flex: 1; height: 1px;
    background: linear-gradient(90deg, transparent, var(--border), transparent);
}
.auth-guest {
    width: 100%; padding: 11px 14px;
    background: transparent;
    border: 1.5px dashed var(--border);
    border-radius: 11px;
    color: var(--text, #0f172a);
    font-weight: 600; font-size: 14px;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center; gap: 8px;
    transition: border-color .15s var(--ease), background .15s var(--ease), color .15s var(--ease);
}
.auth-guest:hover { border-color: var(--primary, #4f46e5); color: var(--primary, #4f46e5); background: rgba(99,102,241,.04); }
.auth-guest svg { transition: transform .2s var(--ease); }
.auth-guest:hover svg { transform: translateX(3px); }
.auth-hint { margin: 10px 0 0; font-size: 11.5px; color: var(--text-muted); text-align: center; line-height: 1.4; }
.auth-consent { display: flex; gap: 8px; align-items: flex-start; font-size: 12px; color: var(--text-muted); line-height: 1.4; margin: 4px 0 10px; text-align: left; }
.auth-consent input[type="checkbox"] { margin-top: 2px; flex-shrink: 0; }
.auth-consent a { color: var(--accent, #6366f1); }

/* Trust strip under the brand — three compact chips with an icon + label.
 * Wraps on narrow screens; each chip keeps its internals inline so icon
 * and label never break across lines. */
.auth-trust {
    list-style: none; padding: 0;
    margin: 10px 0 20px;
    display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 8px;
}
.auth-trust li {
    display: inline-flex; align-items: center; gap: 6px;
    padding: 5px 10px;
    font-size: 11.5px; font-weight: 600; letter-spacing: .01em;
    color: var(--text-soft);
    background: color-mix(in srgb, var(--primary) 7%, var(--bg-elev));
    border: 1px solid color-mix(in srgb, var(--primary) 18%, transparent);
    border-radius: 999px;
    white-space: nowrap;
}
.auth-trust li > :first-child {
    color: var(--primary);
    font-weight: 700;
}

.profile-preview-phone {
    font-size: 12.5px;
    margin-top: 4px;
    letter-spacing: .02em;
}

/* Тёмная тема */
@media (prefers-color-scheme: dark) {
    .auth-card { background: #1e293b; border-color: rgba(148,163,184,.15); }
    .auth-input-wrap { background: #0f172a; border-color: rgba(148,163,184,.2); }
    .auth-input-wrap:focus-within { background: #0b1222; }
    .auth-input-wrap input { color: #f1f5f9; }
    .auth-tabs { background: rgba(99,102,241,.12); }
    .auth-tabs-ink { background: #334155; }
    .auth-guest { color: #cbd5e1; }
}

/* ======================================================================
   WebRTC call UI. Everything lives outside the normal layout flow —
   incoming-card pops in from the top-right; in-call overlay takes over
   the whole viewport. No fancy transitions (yet) — just solid, legible
   controls that work on both desktop and mobile.
   ====================================================================== */
.call-incoming {
    position: fixed; top: 16px; right: 16px; z-index: 5000;
    background: var(--bg, #fff); color: var(--fg, #0f172a);
    border: 1px solid rgba(99,102,241,.3); border-radius: 14px;
    box-shadow: 0 10px 30px rgba(15,23,42,.2);
    padding: 14px 16px; display: flex; align-items: center; gap: 12px;
    min-width: 280px; max-width: 360px;
    animation: call-pulse 1.4s infinite;
}
@keyframes call-pulse {
    0%, 100% { box-shadow: 0 10px 30px rgba(15,23,42,.2), 0 0 0 0 rgba(99,102,241,.35); }
    50%      { box-shadow: 0 10px 30px rgba(15,23,42,.2), 0 0 0 8px rgba(99,102,241,0); }
}
.call-incoming-avatar {
    width: 44px; height: 44px; border-radius: 50%; flex: 0 0 auto;
    background: linear-gradient(135deg,#6366f1,#8b5cf6); color: #fff;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
}
.call-incoming-body { flex: 1; min-width: 0; }
.call-incoming-who  { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-incoming-actions { display: flex; gap: 8px; }

.call-btn {
    width: 42px; height: 42px; border-radius: 50%; border: none;
    display: inline-flex; align-items: center; justify-content: center;
    cursor: pointer; color: #fff;
}
.call-btn svg { width: 22px; height: 22px; }
.call-btn-accept { background: #16a34a; }
.call-btn-accept:hover { background: #15803d; }
.call-btn-reject { background: #dc2626; }
.call-btn-reject:hover { background: #b91c1c; }
.call-btn-ctrl   { background: rgba(15,23,42,.65); }
.call-btn-ctrl:hover { background: rgba(15,23,42,.85); }
.call-btn-ctrl.muted-state { background: rgba(220,38,38,.85); }
.call-btn-ctrl .ico-off { display: none; }
.call-btn-ctrl.muted-state .ico-on  { display: none; }
.call-btn-ctrl.muted-state .ico-off { display: inline-block; }

.call-overlay {
    position: fixed; inset: 0; z-index: 4800;
    background: #0b1222; color: #e2e8f0;
    display: flex; flex-direction: column;
}
.call-overlay[hidden] { display: none; }
.call-remote {
    position: absolute; inset: 0; display: flex;
    align-items: center; justify-content: center;
    background: radial-gradient(circle at 50% 30%, #1e293b 0%, #020617 80%);
}
#call-remote-video {
    width: 100%; height: 100%; object-fit: cover;
}
.call-placeholder {
    position: absolute; inset: 0; display: flex;
    align-items: center; justify-content: center;
    pointer-events: none;
}
.call-placeholder span {
    display: inline-flex; align-items: center; justify-content: center;
    width: 120px; height: 120px; border-radius: 50%;
    background: linear-gradient(135deg,#6366f1,#8b5cf6);
    font-size: 44px; font-weight: 600; color: #fff;
    box-shadow: 0 20px 60px rgba(99,102,241,.35);
}
.call-local {
    position: absolute; right: 20px; top: 80px;
    width: 180px; max-width: 30vw; aspect-ratio: 4 / 3;
    object-fit: cover; border-radius: 14px;
    border: 2px solid rgba(226,232,240,.2);
    background: #020617; transform: scaleX(-1);
}
.call-header {
    position: relative; padding: 20px 24px;
    display: flex; align-items: center; gap: 12px;
    background: linear-gradient(180deg, rgba(2,6,23,.6), rgba(2,6,23,0));
}
.call-peer   { font-weight: 600; font-size: 18px; }
.call-status { font-size: 14px; }
.call-timer  { margin-left: auto; font-variant-numeric: tabular-nums; }
.call-controls {
    position: relative; margin-top: auto;
    display: flex; justify-content: center; gap: 18px;
    padding: 24px; background: linear-gradient(0deg, rgba(2,6,23,.75), rgba(2,6,23,0));
}
.call-controls .call-btn { width: 58px; height: 58px; }
.call-controls .call-btn svg { width: 26px; height: 26px; }

@media (max-width: 480px) {
    .call-local { width: 120px; top: 70px; right: 12px; }
    .call-controls .call-btn { width: 52px; height: 52px; }
}

/* E2E lock indicator — small green chip next to chat title. Only shows
   when the active 1:1 chat has a published peer key and our own keys
   are ready, so "no chip" always means "server can see plaintext". */
.chat-e2e {
    display: inline-flex; align-items: center; gap: 4px;
    font-size: 11px; font-weight: 600; letter-spacing: .01em;
    padding: 2px 8px; border-radius: 999px;
    background: rgba(22,163,74,.12); color: #15803d;
    border: 1px solid rgba(22,163,74,.3);
}
.dark .chat-e2e { background: rgba(22,163,74,.18); color: #86efac; }
