/* ═══════════════════════════════════════════════════════════
   CHAT VIEW — повне вікно чату
   ═══════════════════════════════════════════════════════════ */

/* Контейнер вікна чату (flex-column, займає весь chat-area) */
.chat-view {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    position: relative;
}

/* ─── Посилання в повідомленнях ──────────────────────────── */
.msg-link {
    color: inherit;
    text-decoration: underline;
    text-underline-offset: 2px;
    font-weight: 500;
    word-break: break-all;
    cursor: pointer;
}
.msg-link:hover { opacity: 0.8; }

.link-card {
    display: flex;
    flex-direction: column;
    margin-top: 8px;
    max-width: 320px;
    border-radius: 12px;
    overflow: hidden;
    background: rgba(0, 0, 0, 0.06);
    border-left: 3px solid var(--primary-color);
    cursor: pointer;
}
.link-card:hover { background: rgba(0, 0, 0, 0.1); }
.link-card-image { width: 100%; max-height: 180px; object-fit: cover; display: block; }
.link-card-body { display: flex; flex-direction: column; gap: 2px; padding: 8px 12px 10px; min-width: 0; }
.link-card-host { font-size: 11px; opacity: 0.7; text-transform: lowercase; }
.link-card-title { font-size: 14px; font-weight: 600; line-height: 1.3; word-break: break-word; }
.link-card-desc { font-size: 12.5px; opacity: 0.85; line-height: 1.35; word-break: break-word; }

/* Підтвердження переходу за зовнішнім посиланням */
.link-confirm-overlay {
    position: fixed; inset: 0; z-index: 3000;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(6px);
    display: flex; align-items: center; justify-content: center;
    padding: 16px;
    box-sizing: border-box;
}
.link-confirm {
    width: 100%; max-width: 420px;
    background: var(--sidebar-bg);
    color: var(--text-main, inherit);
    border: 1px solid var(--border-color);
    border-radius: 20px;
    padding: 24px;
    box-shadow: 0 25px 60px -12px rgba(0, 0, 0, 0.4);
}
.link-confirm h4 { margin: 0 0 8px; font-size: 18px; }
.link-confirm p { margin: 0 0 10px; font-size: 14px; line-height: 1.45; }
.link-confirm-url {
    padding: 10px 12px; margin-bottom: 12px;
    border-radius: 10px;
    background: var(--hover-bg, rgba(0, 0, 0, 0.06));
    font-size: 13px; word-break: break-all;
}
.link-confirm-warn { color: var(--text-muted); font-size: 12.5px !important; }
.link-confirm-actions { display: flex; gap: 10px; margin-top: 16px; }
.link-confirm-actions button {
    flex: 1; padding: 12px; border-radius: 12px; font-size: 15px; font-weight: 600; cursor: pointer;
}
.link-confirm-cancel { background: var(--hover-bg, transparent); border: 1px solid var(--border-color); color: inherit; }
.link-confirm-ok { background: var(--primary-color); border: none; color: white; }

/* ─── Закріплене повідомлення ────────────────────────────── */
.pinned-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 7px 14px;
    background: var(--sidebar-bg);
    border-bottom: 1px solid var(--border-color);
    border-left: 3px solid var(--primary-color);
    cursor: pointer;
    flex-shrink: 0;
}
.pinned-banner:hover { background: var(--border-color); }
.pinned-banner-body { display: flex; flex-direction: column; min-width: 0; }
.pinned-banner-title { font-size: 12px; font-weight: 600; color: var(--primary-color); }
.pinned-banner-text { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.msg-pinned-badge { font-size: 11px; margin-right: 4px; }

/* ─── Пошук і медіа (відкриваються з меню «три крапки» в шапці) ───────── */
.chat-panel {
    position: absolute;
    top: 0;
    left: 0; right: 0; bottom: 0;
    z-index: 20;
    display: flex;
    flex-direction: column;
    background: var(--sidebar-bg);
    color: var(--text-main);
}
.chat-panel-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--border-color);
}
.chat-panel-search {
    flex: 1;
    min-width: 0;
    padding: 9px 12px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: inherit;
    font-size: 14px;
    outline: none;
}
.chat-panel-tabs { flex: 1; display: flex; gap: 6px; }
.chat-panel-tabs button {
    padding: 7px 14px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.chat-panel-tabs button.active { background: var(--primary-color); border-color: var(--primary-color); color: white; }
.chat-panel-close { border: none; background: transparent; color: inherit; font-size: 18px; cursor: pointer; padding: 4px 8px; }
.chat-panel-status { padding: 6px 14px; font-size: 12px; color: var(--text-muted); }
.chat-panel-body { flex: 1; overflow-y: auto; padding: 6px 0; }
.chat-panel-more {
    display: block;
    margin: 10px auto;
    padding: 8px 20px;
    border-radius: 10px;
    border: 1px solid var(--border-color);
    background: transparent;
    color: inherit;
    cursor: pointer;
}
.chat-panel-empty { text-align: center; padding: 32px 16px; color: var(--text-muted); font-size: 14px; }
.chat-panel-item { padding: 10px 14px; cursor: pointer; border-bottom: 1px solid var(--border-color); }
.chat-panel-item:hover { background: var(--border-color); }
.chat-panel-item-head { display: flex; justify-content: space-between; gap: 8px; margin-bottom: 2px; }
.chat-panel-item-sender { font-weight: 600; font-size: 13px; }
.chat-panel-item-time { font-size: 12px; color: var(--text-muted); }
.chat-panel-item-text { font-size: 14px; word-break: break-word; }
.chat-file-item { display: flex; align-items: center; gap: 10px; }
.chat-file-meta { display: flex; flex-direction: column; min-width: 0; }
.chat-media-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 3px; padding: 3px; }
.chat-media-cell { width: 100%; aspect-ratio: 1 / 1; object-fit: cover; cursor: pointer; background: var(--border-color); }
.chat-media-video { background-size: cover; background-position: center; position: relative; }
.chat-media-play {
    position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
    color: white; font-size: 26px; text-shadow: 0 1px 6px rgba(0, 0, 0, 0.6);
}

/* ─── Список повідомлень ─────────────────────────────────── */
.messages-scroll {
    flex: 1;
    /* Без цього flex-елемент не стискається менше за висоту свого вмісту (класична пастка flexbox) —
       у кімнаті з багатьма повідомленнями список просто ріс за межі viewport, а .chat-view (overflow:hidden)
       обрізав хвіст без можливості прогорнути: власний скрол .messages-scroll теж не спрацьовував,
       бо сам елемент більше не був обмежений батьківським розміром. */
    min-height: 0;
    overflow-y: auto;
    padding: 20px 24px 8px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    scroll-behavior: smooth;
}
.messages-scroll::-webkit-scrollbar { width: 5px; }
.messages-scroll::-webkit-scrollbar-track { background: transparent; }
.messages-scroll::-webkit-scrollbar-thumb { background: var(--border-color); border-radius: 10px; }

/* Кнопка «завантажити ще» */
.load-more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    margin: 0 auto 12px;
    padding: 8px 20px;
    border: 1px solid var(--border-color);
    border-radius: 20px;
    background: var(--sidebar-bg);
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}
.load-more-btn:hover { background: var(--hover-bg); color: var(--text-main); }
.load-more-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ─── Рядок повідомлення ─────────────────────────────────── */
.msg-row {
    display: flex;
    align-items: flex-end;
    gap: 8px;
    max-width: 72%;
    position: relative;
}
.msg-row.has-mention {
    width: 100%;
    max-width: 100%;
}
.msg-row.has-mention .msg-bubble-wrap {
    width: calc(100% - 42px);
    max-width: calc(100% - 42px);
    flex: 0 1 calc(100% - 42px);
}
.msg-row.has-mention .msg-bubble {
    width: max-content;
    max-width: 100%;
}
.msg-row.own {
    align-self: flex-end;
    flex-direction: row-reverse;
}
.msg-row.other {
    align-self: flex-start;
}

/* Повідомлення одного автора в межах п'яти хвилин утворюють компактну групу. */
.msg-row + .msg-row.same-sender { margin-top: -6px; }
.msg-row.continues-sender-group .msg-avatar { visibility: hidden; }

/* ─── Аватар ─────────────────────────────────────────────── */
.msg-avatar {
    width: 34px;
    height: 34px;
    border-radius: 10px;
    background: linear-gradient(135deg, #6366f1, #4338ca);
    color: white;
    font-size: 13px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}
.msg-avatar-button { padding: 0; border: 0; overflow: hidden; cursor: pointer; }
.msg-avatar-button:disabled { cursor: default; }
.msg-avatar-button .msg-avatar-img { display: block; width: 100%; height: 100%; object-fit: cover; }
.msg-avatar-button:not(:disabled):hover,
.msg-avatar-button:not(:disabled):focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; }
.msg-row .msg-avatar.msg-avatar-img { object-fit: cover; background: none; }
.msg-row.own .msg-avatar {
    background: linear-gradient(135deg, var(--primary-color), #4338CA);
}

/* ─── Бульбашка ──────────────────────────────────────────── */
.msg-bubble-wrap {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-width: 100%;
    min-width: 0; /* без цього flex-елемент не стискається нижче довжини вмісту (довга цитата nowrap розпирала бульбашку за край) */
    position: relative; /* Необхідно для позиціонування inline меню */
}
.msg-row.own .msg-bubble-wrap { align-items: flex-end; }
.msg-row.other .msg-bubble-wrap { align-items: flex-start; }

.msg-sender-name {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--primary-color);
    padding: 0;
    margin: 0 0 2px;
    border: 0;
    background: transparent;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}
.msg-sender-name:hover { text-decoration: underline; }
.msg-sender-name:focus-visible { outline: 2px solid var(--primary-color); outline-offset: 2px; }

.msg-bubble {
    display: flow-root;
    padding: 10px 14px 6px;
    border-radius: 18px;
    font-size: 16px;
    line-height: 1;
    word-break: break-word;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    position: relative;
    transition: background 0.15s;
}

/* Своє повідомлення — синій градієнт */
.msg-row.own .msg-bubble {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    border-bottom-right-radius: 4px;
}

/* Чуже повідомлення — підкладка */
.msg-row.other .msg-bubble {
    background: var(--sidebar-bg);
    color: var(--text-main);
    border: 1px solid var(--border-color);
    border-bottom-left-radius: 4px;
}

/* Keep the dark palette independently tuned for readable white text. */
body.dark-theme .msg-row.own .msg-bubble {
    background: linear-gradient(135deg, #1d4ed8, #1e40af);
    color: #fff;
}
body.dark-theme .msg-row.other .msg-bubble {
    background: #1e293b;
    color: #f8fafc;
}
body.dark-theme .msg-sender-name { color: #86efac; }
body.dark-theme .msg-row.own .msg-time,
body.dark-theme .msg-row.own .msg-edited-badge,
body.dark-theme .msg-row.own .msg-read-ticks,
body.dark-theme .msg-row.own .msg-read-count {
    color: #fff;
    opacity: 0.95;
}
body.dark-theme .msg-row.other .msg-time,
body.dark-theme .msg-row.other .msg-edited-badge {
    color: #cbd5e1;
}
body.dark-theme .msg-row.own .msg-reply-text { color: #fff; opacity: 0.95; }
body.dark-theme .msg-row.other .msg-reply-text { color: #e2e8f0; opacity: 1; }

/* Voice notes should size their bubble to the player instead of filling the
   available message column. */
.msg-bubble:has(> .custom-audio-player) {
    width: fit-content;
    max-width: 100%;
}
.msg-bubble.voice-bubble {
    width: 288px;
    max-width: 100%;
}
.msg-bubble.voice-bubble > .custom-audio-player {
    width: 100%;
}
.msg-row.other .msg-bubble.voice-bubble,
body.dark-theme .msg-row.other .msg-bubble.voice-bubble {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    border-color: transparent;
    color: #fff;
}
.msg-bubble.voice-bubble .msg-sender-name,
.msg-row.other .msg-bubble.voice-bubble .msg-time {
    color: #fff;
}
.msg-bubble.voice-bubble .audio-waveform-container {
    background: #3b82f6;
    border-radius: 10px;
    padding: 0 4px;
}
.msg-row.other .msg-bubble.voice-bubble > .custom-audio-player,
body.dark-theme .msg-row.other .msg-bubble.voice-bubble > .custom-audio-player {
    background: transparent;
    color: #fff;
}
body.dark-theme .msg-bubble.voice-bubble > .custom-audio-player .play-btn {
    background: #3b82f6;
    color: #fff;
}

/* Кругле відео саме по собі вже кругле й компактне — "квадратна" бульбашка
   навколо нього зайва (в обох напрямках, і "own", і "other"). */
.msg-bubble:has(.msg-video-circle-wrap) {
    background: transparent !important;
    border: none !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

/* Hover → показуємо кнопки дій */
.msg-row:hover .msg-actions { opacity: 1; pointer-events: all; }


/* ─── Timestamp і мета ───────────────────────────────────── */
.msg-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 6px;
    clear: both;
    margin: 4px 0 0 auto;
    padding: 0;
}
.msg-time {
    font-size: 11px;
    color: var(--text-muted);
    white-space: nowrap;
}
/* Message metadata appears over the blue outgoing bubble, so use a pale tone
   with enough contrast instead of the muted page color. */
.msg-row.own .msg-time,
.msg-row.own .msg-edited-badge { color: rgba(255, 255, 255, 0.82); }
.msg-row.own .msg-read-ticks,
.msg-row.own .msg-read-count { color: rgba(255, 255, 255, 0.92); }
.msg-edited-badge {
    font-size: 11px;
    color: var(--text-muted);
    font-style: italic;
}

/* ─── Read receipts — галочки (DM) / лічильник (групи) ──────────── */
.msg-read-ticks {
    display: inline-flex;
    align-items: center;
    color: var(--text-muted);
}
.msg-read-ticks.read { color: #3b82f6; }

.msg-read-count {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    font-size: 11px;
    color: #3b82f6;
}

/* ─── Реакції — пілюлі під бульбашкою (як у Telegram) ────────────── */
.msg-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    padding: 0 2px;
}
.msg-reaction-pill {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px 3px 7px;
    border-radius: 14px;
    border: 1px solid transparent;
    background: var(--hover-bg);
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    transition: transform 0.12s ease, background 0.15s, border-color 0.15s, box-shadow 0.15s;
    animation: reactionPop 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    font-family: "ChatEmoji", "Segoe UI Emoji", "Noto Color Emoji", "Apple Color Emoji", "Twemoji Mozilla", sans-serif;
}
.msg-reaction-pill:hover {
    background: var(--border-color);
    transform: translateY(-1px);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.12);
}
.msg-reaction-pill:active { transform: scale(0.94); }
.msg-reaction-pill.mine {
    background: linear-gradient(135deg, rgba(59, 130, 246, 0.16), rgba(59, 130, 246, 0.08));
    border-color: rgba(59, 130, 246, 0.55);
}
.msg-reaction-pill.mine:hover { background: rgba(59, 130, 246, 0.22); }
.msg-reaction-count {
    display: inline-flex;
    align-items: center;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text-muted);
}
.msg-reaction-pill.mine .msg-reaction-count { color: #3b82f6; }
.msg-row.own .msg-reaction-pill {
    background: rgba(255, 255, 255, 0.2);
    border-color: rgba(255, 255, 255, 0.28);
}
.msg-row.own .msg-reaction-pill:hover { background: rgba(255, 255, 255, 0.3); }
.msg-row.own .msg-reaction-pill .msg-reaction-count { color: #fff; }
.msg-row.own .msg-reaction-pill.mine {
    background: rgba(255, 255, 255, 0.9);
    border-color: #fff;
}
.msg-row.own .msg-reaction-pill.mine .msg-reaction-count { color: #1d4ed8; }
.msg-bubble .msg-reactions {
    clear: both;
    margin-top: 6px;
    padding: 0;
}
body.dark-theme .msg-row.own .msg-reaction-pill {
    background: rgba(15, 23, 42, 0.42);
    border-color: rgba(255, 255, 255, 0.22);
}
body.dark-theme .msg-row.own .msg-reaction-pill:hover { background: rgba(15, 23, 42, 0.58); }
body.dark-theme .msg-row.own .msg-reaction-pill .msg-reaction-count { color: #f8fafc; }
body.dark-theme .msg-row.own .msg-reaction-pill.mine {
    background: rgba(96, 165, 250, 0.3);
    border-color: #93c5fd;
}
body.dark-theme .msg-row.own .msg-reaction-pill.mine .msg-reaction-count { color: #fff; }
body.dark-theme .msg-row.other .msg-reaction-pill.mine {
    background: rgba(59, 130, 246, 0.22);
    border-color: rgba(96, 165, 250, 0.7);
}
body.dark-theme .msg-row.other .msg-reaction-pill.mine .msg-reaction-count { color: #bfdbfe; }

@keyframes reactionPop {
    0% { transform: scale(0.4); opacity: 0; }
    70% { transform: scale(1.12); opacity: 1; }
    100% { transform: scale(1); }
}

/* ─── Пікер швидких реакцій у контекстному меню ──────────────────── */
.reaction-picker {
    display: flex;
    flex-wrap: nowrap; /* 6 емодзі мають лишатись в один рядок — інакше "стрибають" по два ряди */
    align-items: center;
    justify-content: space-between;
    gap: 2px;
    padding: 6px 6px 10px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 4px;
}
.reaction-picker-btn {
    border: none;
    background: transparent;
    flex-shrink: 0;
    font-size: 22px;
    line-height: 1;
    padding: 5px;
    border-radius: 50%;
    cursor: pointer;
    transition: transform 0.15s cubic-bezier(0.175, 0.885, 0.32, 1.275), background 0.15s;
    /* Без явного emoji-стеку Windows-браузери інколи беруть системний
       sans-serif і малюють емодзі чорно-білим "плоским" гліфом замість
       кольорового — саме це й виглядало "криво" лише на Windows. */
    font-family: "ChatEmoji", "Segoe UI Emoji", "Noto Color Emoji", "Apple Color Emoji", "Twemoji Mozilla", sans-serif;
}
.reaction-picker-btn:hover {
    background: var(--hover-bg);
    transform: scale(1.35) translateY(-2px);
}
.reaction-picker-btn:active { transform: scale(1.1); }

/* ─── Кнопки дій (edit/delete) ───────────────────────────── */
.msg-actions {
    position: absolute;
    top: -36px;
    opacity: 0;
    pointer-events: none;
    display: flex;
    gap: 4px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 4px;
    box-shadow: 0 4px 16px rgba(0,0,0,0.12);
    transition: opacity 0.15s;
    z-index: 10;
}
.msg-row.own .msg-actions { right: 0; }
.msg-row.other .msg-actions { left: 42px; }

.msg-action-btn {
    width: 28px;
    height: 28px;
    border: none;
    background: transparent;
    color: var(--text-muted);
    border-radius: 6px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.15s;
}
.msg-action-btn:hover { background: var(--hover-bg); color: var(--text-main); }
.msg-action-btn.delete:hover { background: #FEF2F2; color: #EF4444; }
body.dark-theme .msg-action-btn.delete:hover { background: rgba(239,68,68,0.1); }

/* ─── Зображення у повідомленні ──────────────────────────── */
.msg-image {
    max-width: 400px;
    max-height: 400px;
    border-radius: 12px;
    object-fit: contain;
    cursor: pointer;
    display: block;
    transition: filter 0.2s;
    background-color: var(--hover-bg); /* Add background in case image has transparency */
}
.msg-image:hover { filter: brightness(0.95); }

/* ─── Відео у повідомленні ───────────────────────────────── */
.msg-video {
    max-width: 400px;
    max-height: 400px;
    border-radius: 12px;
    display: block;
    background-color: #000;
}

/* ─── Кругле відеоповідомлення (як у Telegram) ──────────────── */
.msg-video-circle-wrap {
    position: relative;
    width: 220px;
    height: 220px;
    cursor: pointer;
}
.msg-video-circle {
    width: 220px;
    height: 220px;
    border-radius: 50%;
    display: block;
    object-fit: cover;
    background-color: #000;
    pointer-events: none; /* клік/тогл — через саму обгортку, не через відео */
}

/* Кнопка "▶" поверх кружечка — зникає, поки відео грає */
.msg-video-circle-play-overlay {
    position: absolute;
    inset: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.25);
    transition: opacity 0.15s;
}
.msg-video-circle-play-overlay svg { margin-left: 3px; } /* оптична корекція трикутника */
.msg-video-circle-wrap.playing .msg-video-circle-play-overlay { opacity: 0; pointer-events: none; }
.msg-video-circle-seek {
    position: absolute;
    left: 15%;
    bottom: 27px;
    z-index: 4;
    width: 70%;
    height: 22px;
    display: flex;
    align-items: center;
    touch-action: none;
    cursor: pointer;
    outline: none;
}
.msg-video-circle-seek-track {
    position: relative;
    width: 100%;
    height: 4px;
    border-radius: 999px;
    background: rgba(255, 255, 255, .42);
    box-shadow: 0 1px 4px rgba(0, 0, 0, .55);
    transition: height .15s ease, background .15s ease;
}
.msg-video-circle-seek-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: var(--seek-progress, 0%);
    border-radius: inherit;
    background: linear-gradient(90deg, #60a5fa, #bfdbfe);
}
.msg-video-circle-seek-thumb {
    position: absolute;
    left: var(--seek-progress, 0%);
    top: 50%;
    width: 11px;
    height: 11px;
    border: 2px solid #fff;
    border-radius: 50%;
    background: #60a5fa;
    box-shadow: 0 1px 5px rgba(0, 0, 0, .55);
    transform: translate(-50%, -50%) scale(.85);
    transition: transform .15s ease;
}
.msg-video-circle-seek:hover .msg-video-circle-seek-track,
.msg-video-circle-seek:focus-visible .msg-video-circle-seek-track {
    height: 6px;
    background: rgba(255, 255, 255, .58);
}
.msg-video-circle-seek:hover .msg-video-circle-seek-thumb,
.msg-video-circle-seek:focus-visible .msg-video-circle-seek-thumb {
    transform: translate(-50%, -50%) scale(1);
}
.msg-video-circle-seek:focus-visible {
    filter: drop-shadow(0 0 3px rgba(96, 165, 250, .9));
}
.msg-video-circle-stop {
    position: absolute;
    top: 12px;
    right: 12px;
    z-index: 2;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    background: rgba(0, 0, 0, 0.6);
    cursor: pointer;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.15s;
}

.persistent-circle-stop {
    position: fixed;
    right: 34px;
    z-index: 10002;
    width: 36px;
    height: 36px;
    padding: 0;
    border: 0;
    border-radius: 50%;
    display: none;
    place-items: center;
    color: white;
    background: rgba(0, 0, 0, 0.65);
    cursor: pointer;
}
.persistent-circle-stop svg {
    width: 16px;
    height: 16px;
    fill: currentColor;
}
.msg-video-circle-wrap.playing .msg-video-circle-stop {
    opacity: 1;
    pointer-events: auto;
}

/* Тривалість — кольоровим текстом поверх кружечка, без плашки/фону */
.msg-video-circle-duration {
    position: absolute;
    left: 50%;
    bottom: 10px;
    transform: translateX(-50%);
    color: #60a5fa;
    font-size: 13px;
    font-weight: 700;
    text-shadow: 0 1px 3px rgba(0, 0, 0, 0.7);
    pointer-events: none;
}

/* ─── Файл у повідомленні ────────────────────────────────── */
/* Фон дає сама бульбашка — картка лишається прозорою й успадковує її колір */
.msg-file {
    display: flex;
    align-items: center;
    gap: 12px;
    min-width: 200px;
    max-width: 320px;
    color: inherit;
    text-decoration: none;
    transition: opacity 0.2s;
}
.msg-file:hover { opacity: 0.85; }

.msg-file-icon {
    font-size: 26px;
    line-height: 1;
    flex-shrink: 0;
}
.msg-file-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
    flex: 1;
}
.msg-file-name {
    font-size: 15px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.msg-file-size {
    font-size: 13px;
    opacity: 0.75; /* не --text-muted: на синій бульбашці він нечитабельний */
}
.msg-file-download {
    flex-shrink: 0;
    opacity: 0.6;
}
.msg-file:hover .msg-file-download { opacity: 1; }

/* ─── Бульбашка «завантажується» (запис голосового / надсилання файлу) ─── */
.msg-uploading {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 160px;
    max-width: 280px;
}
.msg-uploading-spinner {
    width: 18px;
    height: 18px;
    flex-shrink: 0;
    border: 2px solid rgba(255,255,255,0.35);
    border-top-color: currentColor;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
.msg-uploading-label {
    font-size: 14px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Ім'я файлу + кнопка завантаження над плеєром — лише для завантажених
   аудіофайлів (не для голосових, їх і так не завантажують окремо) */
.msg-audio-filename {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 6px;
    max-width: min(260px, 100%);
}
.msg-audio-filename-text {
    font-size: 13px;
    font-weight: 500;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    min-width: 0;
}
.msg-audio-download-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    padding: 2px;
    cursor: pointer;
    color: inherit;
    opacity: 0.7;
    transition: opacity 0.2s;
}
.msg-audio-download-btn:hover { opacity: 1; }

/* Image light-box overlay */
.img-lightbox {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    cursor: pointer; /* zoom-out на темному фоні майже не видно — "рука" біла з контуром, її видно завжди */
    animation: fadeIn 0.2s ease;
}
.img-lightbox img {
    cursor: default;
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    box-shadow: 0 24px 60px rgba(0,0,0,0.5);
}

/* Підпис під фото в бульбашці */
.msg-caption {
    margin-top: 6px;
    white-space: pre-wrap;
    overflow-wrap: anywhere; /* довге слово ламається, а не розпирає бульбашку */
}

.now-playing-bar {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
    box-sizing: border-box;
    padding: 0 8px 0 14px;
    border: 0;
    border-bottom: 1px solid rgba(50, 168, 82, 0.35);
    box-shadow: inset 4px 0 0 var(--primary-color);
    color: var(--text-main);
    background: linear-gradient(90deg, rgba(50, 168, 82, 0.14), var(--sidebar-bg) 72%);
}
.now-playing-toggle {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 50%;
    color: var(--primary-color);
    background: transparent;
    cursor: pointer;
}
.now-playing-toggle:hover { background: var(--hover-bg); }
.now-playing-toggle svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.now-playing-jump {
    display: flex;
    align-items: center;
    gap: 10px;
    flex: 1;
    min-width: 0;
    padding: 10px 0;
    border: 0;
    color: inherit;
    text-align: left;
    background: transparent;
    cursor: pointer;
}
.now-playing-jump:hover .now-playing-label { color: var(--primary-color); }
.now-playing-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.now-playing-hint { color: var(--text-muted); font-size: 12px; white-space: nowrap; }
.now-playing-stop {
    display: grid;
    place-items: center;
    width: 34px;
    height: 34px;
    flex: 0 0 auto;
    border: 0;
    border-radius: 50%;
    color: var(--text-muted);
    background: transparent;
    cursor: pointer;
}
.now-playing-stop:hover { color: var(--text-main); background: var(--hover-bg); }
.now-playing-stop svg { width: 18px; height: 18px; fill: currentColor; }
.persistent-media-host { position: fixed; inset: 0; z-index: 10000; pointer-events: none; }
.mobile-now-playing-bubble {
    position: fixed;
    z-index: 11000;
    right: 16px;
    bottom: calc(18px + env(safe-area-inset-bottom, 0px));
    width: 62px;
    height: 62px;
    display: none;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    background: var(--sidebar-bg);
    box-shadow: 0 5px 18px rgba(0,0,0,.28);
}
.mobile-now-playing-toggle {
    display: grid;
    place-items: center;
    width: 100%;
    height: 100%;
    padding: 0;
    border: 0;
    border-radius: 50%;
    color: var(--primary-color);
    background: transparent;
    cursor: pointer;
}
.mobile-now-playing-toggle svg { width: 25px; height: 25px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.mobile-now-playing-stop {
    position: absolute;
    top: -3px;
    right: -4px;
    display: grid;
    place-items: center;
    width: 23px;
    height: 23px;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-muted);
    background: var(--sidebar-bg);
    cursor: pointer;
}
.mobile-now-playing-stop svg { width: 12px; height: 12px; fill: currentColor; }

/* iOS має власні emoji-гліфи; на інших платформах лишаємо Noto/Segoe першими. */
html.ios-device .msg-reaction-pill > span:first-child,
html.ios-device .reaction-picker-btn,
html.ios-device .composer-emoji-btn {
    font-family: "ChatEmoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif;
}
html.ios-device .msg-textarea {
    font-family: "Inter", "ChatEmoji", "Apple Color Emoji", "Noto Color Emoji", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

.msg-video-with-caption { max-width: 100%; }
.msg-video-with-caption .msg-caption { padding: 0 2px; }
.mention-suggestions {
    position: absolute;
    z-index: 30;
    bottom: calc(100% + 8px);
    left: 0;
    display: flex;
    flex-direction: column;
    min-width: 190px;
    max-width: min(320px, 80vw);
    max-height: 220px;
    overflow: auto;
    padding: 4px;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--sidebar-bg);
    box-shadow: 0 8px 24px rgba(0,0,0,.22);
}
.mention-suggestion {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border: 0;
    border-radius: 6px;
    color: var(--text-color);
    text-align: left;
    background: transparent;
    cursor: pointer;
}
.mention-suggestion.active,
.mention-suggestion:hover,
.mention-suggestion:focus-visible { background: rgba(59, 130, 246, 0.14); color: #2563eb; outline: none; }
.mention-suggestion-avatar,
.mention-profile-avatar {
    width: 32px;
    height: 32px;
    flex: 0 0 32px;
    border-radius: 50%;
    object-fit: cover;
}
.mention-profile-initial {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: var(--hover-bg);
    color: var(--text-main);
    font-size: 13px;
    font-weight: 700;
}
.mention-suggestion-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.mention-anchor {
    position: relative;
    display: inline-block;
    vertical-align: baseline;
    line-height: inherit;
    max-width: 100%;
    white-space: normal;
    cursor: pointer;
    outline: none;
}
.message-mention {
    display: inline;
    border-radius: 4px;
    padding: 0 1px;
    -webkit-box-decoration-break: clone;
    box-decoration-break: clone;
    overflow-wrap: anywhere;
    color: #1d4ed8;
    background: rgba(59, 130, 246, 0.13);
    font-weight: 600;
}
.msg-row.own .message-mention {
    color: #fff;
    background: #1e40af;
}
.mention-anchor:hover .message-mention,
.mention-anchor:focus-visible .message-mention { background: rgba(59, 130, 246, 0.28); }
.msg-row.own .mention-anchor:hover .message-mention,
.msg-row.own .mention-anchor:focus-visible .message-mention { background: #1e3a8a; }
.mention-profile-card {
    position: absolute;
    z-index: 70;
    left: 50%;
    bottom: calc(100% + 8px);
    display: flex;
    align-items: center;
    gap: 9px;
    width: max-content;
    max-width: min(260px, 75vw);
    padding: 8px 11px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--sidebar-bg);
    color: var(--text-main);
    box-shadow: 0 6px 20px rgba(0, 0, 0, 0.24);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transform: translate(-50%, 4px);
    transition: opacity 0.12s ease, transform 0.12s ease, visibility 0.12s;
}
.mention-anchor:hover .mention-profile-card,
.mention-anchor:focus .mention-profile-card,
.mention-anchor:focus-within .mention-profile-card {
    opacity: 1;
    visibility: visible;
    transform: translate(-50%, 0);
}
.mention-profile-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 600; }
body.dark-theme .message-mention { color: #bfdbfe; background: rgba(59, 130, 246, 0.24); }
body.dark-theme .msg-row.own .message-mention { color: #fff; background: #1e40af; }
body.dark-theme .mention-suggestion.active,
body.dark-theme .mention-suggestion:hover,
body.dark-theme .mention-suggestion:focus-visible { color: #bfdbfe; }
.emoji-toggle-btn {
    flex: 0 0 auto;
    width: 34px;
    height: 34px;
    border: 0;
    border-radius: 50%;
    color: var(--text-muted);
    background: transparent;
    padding: 6px;
    cursor: pointer;
}
.emoji-toggle-btn svg { display: block; width: 22px; height: 22px; }
.emoji-toggle-btn:hover { background: var(--hover-bg); color: var(--primary-color); }
.composer-emoji-picker {
    position: absolute;
    z-index: 40;
    right: 4px;
    bottom: calc(100% + 8px);
    display: grid;
    grid-template-columns: repeat(8, minmax(0, 1fr));
    gap: 2px;
    box-sizing: border-box;
    width: min(324px, 88vw);
    max-height: 250px;
    overflow-x: hidden;
    overflow-y: auto;
    padding: 8px;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    background: var(--sidebar-bg);
    box-shadow: 0 8px 24px rgba(0,0,0,.22);
}
.composer-emoji-btn {
    min-width: 0;
    height: 38px;
    padding: 0;
    border: 0;
    border-radius: 8px;
    background: transparent;
    font: 23px/1 "ChatEmoji", "Segoe UI Emoji", "Noto Color Emoji", "Apple Color Emoji", sans-serif;
    cursor: pointer;
}
.composer-emoji-btn:hover { background: var(--hover-bg); }

/* Фото з підписом (як у Telegram): бульбашка рівно по ширині фото, фото впритул до країв,
   підпис переноситься під ним. width: min-content дає ширину найширшого блоку, а мінімальна ширина
   підпису (overflow-wrap: anywhere) — один символ, тож ширину задає саме фото. */
.msg-bubble:has(.msg-photo-captioned) { padding: 0; }
.msg-bubble:has(.msg-photo-captioned) > .msg-sender-name {
    margin: 8px 12px 6px;
    max-width: calc(100% - 24px);
    overflow-wrap: anywhere;
}
.msg-bubble:has(.msg-photo-captioned) > .msg-meta { padding: 0 12px 4px; }
.msg-bubble:has(.msg-photo-captioned) > .msg-reactions { padding: 0 12px 8px; }
.msg-photo-captioned {
    display: flex;
    flex-direction: column;
    /* Фіксована ширина (як у Telegram): вузьке фото центрується, з боків лишаються смуги фону, підпис займає всю ширину.
       Рядок з таким фото не обмежуємо 72%/88% (див. нижче), щоб бульбашка росла разом із блоком, а не фото вилазило за неї. */
    width: 100%;
}
/* Ширину задає бульбашка (а не фото), а max-width: 100% не дає їй вийти за межі обгортки — інакше фото вилазить за бульбашку */
.msg-bubble:has(.msg-photo-captioned) { width: min(380px, calc(100vw - 110px)); }
.msg-row:has(.msg-photo-captioned) { max-width: calc(100% - 8px); }
/* На ПК чат стоїть праворуч від списку кімнат (~460px), тож блок стискається разом із вікном, а не лише на телефоні */
@media (min-width: 769px) {
    .msg-bubble:has(.msg-photo-captioned) { width: clamp(200px, calc(100vw - 500px), 380px); }
}
.msg-photo-captioned .msg-photo-frame .msg-image {
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 420px;
    margin: 0 auto;
    object-fit: contain;
}
.msg-photo-frame {
    position: relative;
    overflow: hidden;
    display: block;
    cursor: pointer; /* уся смуга клікабельна — відкриває повне фото */
    background: var(--hover-bg); /* суцільний фон замість blur: filter: blur на багатьох фото гальмує слабкі телефони */
}
.msg-bubble > .msg-photo-captioned:first-child .msg-photo-frame {
    border-radius: 17px 17px 0 0;
}
.msg-photo-captioned .msg-image { border-radius: 0; }
.msg-photo-captioned .msg-caption {
    overflow-wrap: anywhere;
    margin-top: 0;
    padding: 8px 14px 4px;
    text-align: left;
}

/* Форма підтвердження відправки фото */
.img-confirm-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 16px;
    z-index: 10001;
    animation: fadeIn 0.15s ease;
}
.img-confirm-card {
    width: 100%;
    max-width: 460px;
    max-height: 100%;
    display: flex;
    flex-direction: column;
    gap: 12px;
    padding: 18px;
    box-sizing: border-box;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
}
.img-confirm-title { font-size: 17px; font-weight: 600; color: var(--text-main); }
.img-confirm-preview {
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--hover-bg);
    border-radius: 12px;
    overflow: hidden;
}
.img-confirm-preview img {
    max-width: 100%;
    max-height: 50vh;
    object-fit: contain;
    display: block;
}
.img-confirm-caption {
    width: 100%;
    box-sizing: border-box;
    padding: 11px 14px;
    font-size: 16px; /* 16px — щоб iOS не зумив поле при фокусі */
    color: var(--text-main);
    background: var(--hover-bg);
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    outline: none;
    resize: vertical; /* ширину тягнути не можна — поле не розпирає модалку */
}
.img-confirm-caption:focus { border-color: var(--primary-color); }
.img-confirm-actions { display: flex; justify-content: flex-end; gap: 10px; }
.img-confirm-btn {
    padding: 10px 18px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    border: 1px solid transparent;
}
.img-confirm-btn.primary { background: var(--primary-color); color: #fff; }
.img-confirm-btn.primary:hover { filter: brightness(1.08); }
.img-confirm-btn.secondary { background: transparent; color: var(--text-main); border-color: var(--border-color); }
.img-confirm-btn.secondary:hover { background: var(--hover-bg); }

/* Панель дій поверх лайтбокса */
.lightbox-toolbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: linear-gradient(to bottom, rgba(0,0,0,0.6), transparent);
    cursor: default;
}
.lightbox-name {
    flex: 1;
    min-width: 0;
    color: #fff;
    font-size: 15px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.lightbox-download {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    border-radius: 8px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: background 0.2s;
}
.lightbox-download:hover { background: rgba(255,255,255,0.28); }

.lightbox-close {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: rgba(255,255,255,0.15);
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    transition: background 0.2s;
}
.lightbox-close:hover { background: rgba(255,255,255,0.28); }

/* ─── Системні повідомлення ──────────────────────────────── */
.msg-system {
    align-self: center;
    background: var(--hover-bg);
    color: var(--text-muted);
    font-size: 16px;
    font-weight: 500;
    padding: 4px 14px;
    border-radius: 20px;
    margin: 8px 0;
    border: 1px solid var(--border-color);
}

/* ─── Видалене повідомлення ──────────────────────────────── */
.msg-bubble.redacted {
    opacity: 0.45;
    font-style: italic;
}

/* ─── Typing indicator ───────────────────────────────────── */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 24px 10px;
    min-height: 36px;
    color: var(--text-muted);
    font-size: 13px;
}
.typing-dots {
    display: flex;
    gap: 4px;
    align-items: center;
}
.typing-dot {
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: typing-bounce 1.2s infinite ease-in-out;
}
.typing-dot:nth-child(1) { animation-delay: 0s; }
.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing-bounce {
    0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
    30% { transform: translateY(-6px); opacity: 1; }
}

/* ─── Панель введення ────────────────────────────────────── */
.chat-input-bar {
    display: flex;
    align-items: flex-end; /* Кнопки лишаються внизу, коли поле росте на кілька рядків */
    gap: 5px;
    padding: 14px 16px;
    min-height: 68px; /* Було жорстко height: 68px — не давало полю вводу рости */
    box-sizing: border-box;
    background: var(--sidebar-bg);
    border-top: 1px solid var(--border-color);
    position: relative;
}
.chat-input-bar-readonly {
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 14px;
    text-align: center;
}

/* Текст повідомлення: зберігає введені переноси рядків (раніше багаторядкове повідомлення виглядало одним рядком) */
.msg-text {
    line-height: normal;
    white-space: pre-wrap;
}

/* ─── «Реакції» і «Переглянули» всередині спливної панелі повідомлення (як у Telegram) ───────── */
/* Рядки «N реакцій» / «Переглянули» з аватарками */
.context-people-row {
    gap: 10px;
}
.context-people-row > span:first-of-type:not(.context-avatar-stack) {
    flex: 1 1 auto;
    min-width: 0;
}
.context-avatar-stack {
    display: inline-flex;
    margin-left: auto;
    flex-shrink: 0;
}
.context-avatar-stack img,
.context-stack-letter {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    object-fit: cover;
    border: 2px solid var(--sidebar-bg);
    box-sizing: border-box;
    margin-left: -8px;
    flex-shrink: 0;
}
.context-avatar-stack > :first-child { margin-left: 0; }
.context-stack-letter {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6366f1, #4338ca);
    color: #fff;
    font-size: 11px;
    font-weight: 700;
}

/* Підекран: «← Назад» + список людей. Панель трохи ширша, щоб вміщати ім'я, дату й емодзі.
   Колір задаємо явно: панель лежить усередині повідомлення, і біле тло-колір власної бульбашки
   (color: #fff) успадковувався б іменами — на білій панелі вони були б непомітні. */
.custom-context-menu.is-subview {
    width: 300px;
    min-width: 0;
    max-width: calc(100vw - 16px);
    box-sizing: border-box;
}
.custom-context-menu,
.context-person-name,
.context-back,
.context-people-row {
    color: var(--text-main, #111);
}
.context-back {
    display: flex;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    background: transparent;
    border: none;
    border-bottom: 1px solid var(--border-color);
    color: var(--text-main);
    font-size: 15px;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
}
.context-back:hover { background: var(--hover-bg); }
.context-people-list {
    max-height: min(320px, 50vh);
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 0;
    scrollbar-width: thin;
}
.context-person {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px 14px;
}
.context-person:hover { background: var(--hover-bg); }
.context-person-avatar {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border-radius: 50%;
    object-fit: cover;
}
.context-person-letter {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #6366f1, #4338ca);
    color: #fff;
    font-weight: 700;
    font-size: 15px;
}
.context-person-text {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-width: 0;
}
.context-person-name {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-main, #111);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.context-person-sub {
    font-size: 12px;
    color: var(--text-muted);
}
.context-person-emoji { flex-shrink: 0; font-size: 22px; }
.context-people-empty {
    padding: 20px 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
}

/* Підказка про клавіші під полем вводу — лише там, де є клавіатура й миша */
.composer-hint {
    flex-shrink: 0;
    box-sizing: border-box;
    height: 19px; /* точна висота підказки під полем вводу */
    padding: 0 18px 6px;
    background: var(--sidebar-bg);
    color: var(--text-muted);
    font-size: 11px;
    line-height: 1.2;
    text-align: left;
    user-select: none;
}
@media (pointer: coarse), (max-width: 700px) {
    .composer-hint { display: none; }
}

/* Стрілка «до низу» з лічильником нових повідомлень */
.jump-to-bottom-btn {
    position: absolute;
    top: -54px;
    right: 20px;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: 1px solid var(--border-color);
    background: var(--sidebar-bg);
    color: var(--text-color, inherit);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5;
}
.jump-to-bottom-btn:hover { background: var(--border-color); }
.jump-to-bottom-badge {
    position: absolute;
    top: -8px;
    right: -4px;
    min-width: 20px;
    height: 20px;
    padding: 0 5px;
    box-sizing: border-box;
    border-radius: 10px;
    background: var(--primary-color);
    color: white;
    font-size: 11px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}

.input-attach-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    background: var(--hover-bg);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.input-attach-btn:hover { background: var(--border-color); color: var(--text-main); }

.input-wrapper {
    position: relative;
    flex: 1;
    min-width: 0; /* flex-child без цього не стискається менше вмісту — виштовхувало send-btn за екран */
    background: var(--hover-bg);
    border: 1.5px solid var(--border-color);
    border-radius: 20px;
    display: flex;
    align-items: center; /* Центруємо текст по вертикалі, поки один рядок */
    padding: 0 8px;
    transition: border-color 0.2s, box-shadow 0.2s;
    min-height: 40px; /* Було жорстко height: 40px — обрізало 2+ рядки */
    box-sizing: border-box;
}
.input-wrapper:focus-within {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
    background: var(--sidebar-bg);
}

/* Textarea */
.msg-textarea {
    flex: 1;
    min-width: 0;
    border: none;
    background: transparent;
    color: var(--text-main);
    font-size: 16px;
    line-height: 20px;
    height: 20px; /* Стартова висота одного рядка — далі росте через JS (autoResizeTextarea) */
    max-height: 110px; /* ~5 рядків, далі — внутрішній скрол */
    padding: 0;
    margin: 0;
    resize: none;
    outline: none;
    overflow-y: auto;
    font-family: "Inter", "ChatEmoji", "Segoe UI Emoji", "Noto Color Emoji", -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple Color Emoji", Roboto, Helvetica, Arial, sans-serif;
    display: block;
    box-sizing: border-box; /* щоб JS-розрахунок висоти (scrollHeight) збігався зі style.height */
}
.msg-textarea::placeholder { color: var(--text-muted); line-height: 20px; }
.msg-textarea::-webkit-scrollbar { width: 4px; }

.send-btn {
    width: 38px;
    height: 38px;
    flex-shrink: 0;
    border: none;
    border-radius: 50%;
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    box-shadow: 0 4px 12px rgba(59,130,246,0.3);
}
.send-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(59,130,246,0.4); }
.send-btn:active { transform: translateY(0); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }

/* ─── Банер редагування ──────────────────────────────────── */
.editing-banner {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 16px;
    background: rgba(59,130,246,0.08);
    border-top: 1px solid rgba(59,130,246,0.2);
    color: var(--text-main);
    font-size: 13px;
}
.editing-banner-label {
    font-weight: 600;
    color: #3b82f6;
    white-space: nowrap;
}
.editing-banner-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    color: var(--text-muted);
}
.editing-cancel-btn {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    display: flex;
    transition: background 0.15s;
}
.editing-cancel-btn:hover { background: var(--hover-bg); }

/* ─── Завантаження / порожній стан ──────────────────────── */
.chat-loading {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    flex-direction: column;
    gap: 12px;
    font-size: 14px;
}
.chat-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ─── Контекстне меню (правок клік) ─── */
.custom-context-menu {
    position: fixed;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.2);
    padding: 6px;
    display: flex;
    flex-direction: column;
    gap: 2px;
    z-index: 1000;
    min-width: 150px;
    animation: scaleIn 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    /* Меню й так відкривається довгим натисканням — без цього те саме довге
       натискання ще й запускало нативне виділення тексту/меню браузера
       ("Перекласти", "Копіювати", "Знімок"), яке лягало ПОВЕРХ нашого. */
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    user-select: none;
}
/* Меню з реакціями має вміщати рівно 6 емодзі в один рядок — інакше вони
   переносяться на другий ряд і "стрибають" не на своє місце. */
.custom-context-menu:has(.reaction-picker) {
    min-width: 244px;
    /* Реакцій більше, ніж вміщається: меню не ширше за екран, а ряд емодзі гортається вбік */
    max-width: calc(100vw - 24px);
    box-sizing: border-box;
}
.custom-context-menu .reaction-picker {
    overflow-x: auto;
    justify-content: flex-start;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
}
.custom-context-menu .reaction-picker::-webkit-scrollbar { display: none; }

.custom-context-menu.inline-context {
    position: absolute;
    bottom: calc(100% + 5px); /* Зверху повідомлення */
    right: 0;
    top: auto;
    z-index: 10000;
}
.msg-row.other .custom-context-menu.inline-context {
    right: auto;
    left: 42px; /* Зсув від аватарки */
}
/* Якщо зверху не вистачає місця (JS: positionInlineContextMenu) — відкриваємо
   панель вниз від повідомлення замість вгору. */
.custom-context-menu.inline-context.flip-down {
    bottom: auto;
    top: calc(100% + 5px);
}
.context-menu-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    background: transparent;
    border: none;
    width: 100%;
    text-align: left;
    color: var(--text-main);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}
.context-menu-item:hover { background: var(--hover-bg); }
.context-menu-item.danger { color: #EF4444; }
.context-menu-item.danger:hover { background: #FEF2F2; }
body.dark-theme .context-menu-item.danger:hover { background: rgba(239, 68, 68, 0.1); }
.context-overlay {
    position: fixed;
    inset: 0;
    z-index: 9999;
}

/* ─── "Переглянули" — секція в контекстному меню ─── */
.context-menu-divider {
    height: 1px;
    background: var(--border-color);
    margin: 4px 2px;
}
.custom-context-menu .context-menu-section-title {
    padding: 4px 14px 2px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-muted) !important;
}
.custom-context-menu .context-menu-viewers-empty {
    padding: 4px 14px 8px;
    font-size: 13px;
    color: var(--text-muted) !important;
}
.context-menu-viewers {
    display: flex;
    flex-direction: column;
    gap: 2px;
    max-height: 180px;
    overflow-y: auto;
    padding-bottom: 4px;
}
.custom-context-menu .context-menu-viewer-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 14px;
    font-size: 13px;
    color: var(--text-main) !important;
    white-space: nowrap;
}
.custom-context-menu .context-menu-viewer-name {
    color: var(--text-main) !important;
}
.context-menu-viewer-avatar {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    flex-shrink: 0;
    background: linear-gradient(135deg, #6366f1, #4338ca);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    display: flex;
    align-items: center;
    justify-content: center;
}
.context-menu-viewer-name {
    overflow: hidden;
    text-overflow: ellipsis;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* ─── Медіа запити ───────────────────────────────────────── */
@media (max-width: 768px) {
    .chat-view .now-playing-bar { display: none !important; }
    .messages-scroll { padding: 12px 12px 8px; }
    .chat-input-bar { padding: 10px 12px 14px; }
    .msg-row { max-width: 88%; }
    .msg-image { max-width: 220px; }
    .msg-video { max-width: 220px; }
    .msg-file { min-width: 0; max-width: 240px; }
}

.recording-ripple {
    animation: ripple 1.5s infinite;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
}
@keyframes ripple {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }
    100% {
        box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
    }
}

/* ── Waveform Recording UI ── */
.recording-waveform-wrapper {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 10px;
    background: rgba(239, 68, 68, 0.05);
    border: 1.5px solid rgba(239, 68, 68, 0.3);
    border-radius: 20px;
    padding: 0 14px;
    height: 40px;
    box-sizing: border-box;
    overflow: hidden;
}

.recording-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #e53e3e;
    flex-shrink: 0;
    animation: blink-dot 1s infinite;
}

@keyframes blink-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.2; }
}

.waveform-canvas {
    flex: 1;
    height: 40px;
    max-width: 100%;
}

/* ── Video-circle Recording UI — повноекранний оверлей, як у Telegram ── */
.video-record-overlay {
    position: fixed;
    inset: 0;
    z-index: 9000;
    background: rgba(10, 12, 16, 0.94);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 18px;
    padding: 24px;
    box-sizing: border-box;
    animation: fadeIn 0.15s ease;
}
.video-record-spacer { flex: 1; max-height: 10vh; }

.video-record-circle-box {
    position: relative;
    width: min(78vw, 320px);
    height: min(78vw, 320px);
    flex-shrink: 0;
    border-radius: 50%;
    animation: pulse-ring 1.4s infinite;
    isolation: isolate;
}

@keyframes pulse-ring {
    0%, 100% { box-shadow: 0 0 0 3px #e53e3e; }
    50% { box-shadow: 0 0 0 3px rgba(229, 62, 62, 0.4); }
}

.video-record-circle {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
    background-color: #000;
    display: block;
}
/* Дзеркало лише для фронтальної камери — клас виставляє JS (video-recorder.js) */
.video-record-circle.mirrored {
    transform: scaleX(-1);
}

.video-record-flip-btn {
    position: absolute;
    right: 6px;
    bottom: 6px;
    flex-shrink: 0;
    width: 40px;
    height: 40px;
    border: 2px solid rgba(255, 255, 255, 0.85);
    border-radius: 50%;
    background: rgba(30, 41, 59, 0.65);
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
.video-record-flip-btn:hover { background: rgba(30, 41, 59, 0.9); }

.video-record-hint {
    color: rgba(255, 255, 255, 0.55);
    font-size: 13px;
}

.video-record-bar {
    flex: 1;
    max-height: 10vh;
    width: 100%;
    max-width: 360px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.video-record-timer {
    display: flex;
    align-items: center;
    gap: 8px;
}
.video-record-timer .recording-timer-label { font-size: 16px; }

.video-record-cancel-btn,
.video-record-send-btn {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
}
.video-record-cancel-btn {
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
}
.video-record-cancel-btn:hover { background: rgba(255, 255, 255, 0.18); }
.video-record-send-btn {
    background: linear-gradient(135deg, #3b82f6, #2563eb);
    color: #fff;
    box-shadow: 0 4px 14px rgba(59, 130, 246, 0.5);
}
.video-record-send-btn:hover { transform: translateY(-1px); }

.recording-timer-label {
    font-size: 12px;
    font-weight: 600;
    color: #e53e3e;
    flex-shrink: 0;
    white-space: nowrap;
}

/* ── Reply Quote в повідомленні ── */
.msg-reply-quote {
    background: rgba(0, 0, 0, 0.08);
    border-left: 3px solid #3b82f6;
    border-radius: 6px;
    padding: 5px 10px;
    margin-bottom: 6px;
    cursor: pointer;
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    overflow: hidden;
    transition: background 0.15s;
}
.msg-reply-quote:hover {
    background: rgba(0, 0, 0, 0.14);
}
.msg-row.own .msg-reply-quote {
    background: rgba(255, 255, 255, 0.15);
    border-left-color: rgba(255, 255, 255, 0.7);
}
.msg-row.own .msg-reply-quote:hover {
    background: rgba(255, 255, 255, 0.22);
}
.msg-reply-sender {
    display: block;
    font-size: 12px;
    font-weight: 700;
    color: #3b82f6;
    margin-bottom: 2px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.msg-row.own .msg-reply-sender {
    color: rgba(255, 255, 255, 0.9);
}
.msg-reply-text {
    display: block;
    font-size: 13px;
    opacity: 0.75;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* ── Message Highlight (scroll-to effect) ── */
@keyframes msg-highlight-fade {
    0%   { background: rgba(59, 130, 246, 0.25); }
    100% { background: transparent; }
}
.msg-highlight .msg-bubble {
    animation: msg-highlight-fade 1.5s ease-out forwards;
}


.custom-audio-player {
    display: flex;
    align-items: center;
    gap: 12px;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 6px 14px 6px 6px;
    /* Раніше фіксовані 260px (разом із відступами бульбашки ~290px) на вузькому екрані виходили за край
       повідомлення. min(260px, 100%) — до 260px, але не ширше за бульбашку; відсоток не збільшує мінімальну
       ширину вмісту, тож бульбашка може стиснутись. */
    width: min(260px, 100%);
    max-width: 100%;
    min-width: 0;
    box-sizing: border-box;
    color: inherit;
}

.custom-audio-player .play-btn {
    background: #3b82f6;
    color: white;
    border: none;
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    transition: transform 0.2s, background 0.2s;
}
.custom-audio-player .play-btn:hover {
    transform: scale(1.05);
    background: #2563eb;
}
.msg-row.own .custom-audio-player .play-btn {
    background: white;
    color: #3b82f6;
}

.audio-waveform-container {
    flex-grow: 1;
    min-width: 0; /* дозволяє хвилі стискатись, а не розпирати плеєр */
    position: relative;
    height: 32px;
    display: flex;
    align-items: center;
    cursor: pointer;
}

.audio-waveform-canvas {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none; /* клік/seek обробляє контейнер, canvas лише малює */
}

.audio-time {
    font-size: 12px;
    font-weight: 500;
    min-width: 32px;
    text-align: right;
    opacity: 0.9;
}
