/* rchat UI. Palette, dark theme, avatar colours and bubble/reaction styles come from echat. */

:root {
    --primary: #5b8fd9;
    --primary-dark: #4a7bc8;
    --background: #e8e8e8;
    --surface: #d8d8d8;
    --surface-raised: #f4f4f4;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --divider: #c8c8c8;
    --border: #b0b0b0;
    --success: #10b981;
    --error: #ef4444;
    --surface-variant: #d0d0d0;
    --message-sent: #c5ddf0;
    --message-received: #f0f0f0;
    --left-panel-bg: #d8d8d8;
    --left-header-bg: #5b8fd9;
    --right-header-bg: #d8d8d8;
    --shadow: rgba(0, 0, 0, 0.12);
    --reaction: #5ba642;
    color-scheme: light;
}

[data-theme="dark"] {
    --primary: #60a5fa;
    --primary-dark: #3b82f6;
    --background: #111827;
    --surface: #0f172a;
    --surface-raised: #1e293b;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --divider: #1f2937;
    --border: #374151;
    --success: #34d399;
    --error: #f87171;
    --surface-variant: #1e293b;
    --message-sent: #1e3a5f;
    --message-received: #1f2937;
    --left-panel-bg: #0f172a;
    --left-header-bg: #1e3a5f;
    --right-header-bg: #0f172a;
    --shadow: rgba(0, 0, 0, 0.4);
    color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body, #app {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-size: 14px;
    line-height: 1.5;
    color: var(--text-primary);
    background: var(--surface);
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; font-weight: 600; }
h2 { font-size: 16px; font-weight: 600; margin-bottom: 10px; }
h3 { font-size: 16px; font-weight: 600; }
h4 { font-size: 13px; font-weight: 600; margin: 14px 0 6px; color: var(--text-secondary); text-transform: uppercase; letter-spacing: .3px; }
.muted { color: var(--text-secondary); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, Consolas, monospace; }
.break { word-break: break-all; }
.grow { flex: 1; min-width: 0; }
.spacer { flex: 1; }
.hint { font-size: 12px; color: var(--text-secondary); margin-top: 6px; }
.error { color: var(--error); margin-top: 8px; }

.boot { height: 100%; display: flex; align-items: center; justify-content: center; font-size: 22px; color: var(--text-secondary); }

/* ─── Controls ─── */

input, textarea, select {
    font: inherit;
    color: var(--text-primary);
    background: var(--background);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 8px 10px;
}
input:focus, textarea:focus { outline: none; border-color: var(--primary); }
label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--text-secondary); }
label.check { flex-direction: row; align-items: center; gap: 8px; color: var(--text-primary); }
label.check input { width: auto; }

.btn {
    font: inherit;
    border: 1px solid var(--border);
    background: var(--surface-raised);
    color: var(--text-primary);
    border-radius: 4px;
    padding: 7px 14px;
    cursor: pointer;
}
.btn:hover:not(:disabled) { filter: brightness(0.96); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--primary); border-color: var(--primary); color: #fff; }
.btn.danger { color: var(--error); }
.btn.small { padding: 3px 10px; font-size: 12px; }
.btn.wide { width: 100%; }

.icon-btn {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    width: 38px;
    height: 38px;
    border-radius: 4px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    flex-shrink: 0;
}
.icon-btn:hover { background: rgba(127, 127, 127, 0.18); text-decoration: none; }

.tabs { display: flex; gap: 4px; margin-bottom: 14px; border-bottom: 1px solid var(--divider); }
.tab { font: inherit; background: none; border: none; padding: 8px 14px; cursor: pointer; color: var(--text-secondary); border-bottom: 2px solid transparent; }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.card { background: var(--surface-raised); border-radius: 6px; padding: 18px; box-shadow: 0 1px 3px var(--shadow); }

/* ─── Auth and plain pages ─── */

.center-page { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card form, .grid-form { display: flex; flex-direction: column; gap: 12px; }
.auth-logo { font-size: 28px; font-weight: 700; color: var(--primary); text-align: center; margin-bottom: 14px; }

.page { max-width: 900px; margin: 0 auto; padding: 16px; display: flex; flex-direction: column; gap: 14px; }
.page-header { display: flex; align-items: center; gap: 8px; }
.inline-form { display: flex; gap: 8px; margin-top: 8px; }
.inline-form input { flex: 1; min-width: 0; }
label.retention { display: flex; flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; margin-top: 12px; text-align: left; }
.retention select { width: auto; }
.totp-qr { display: block; width: 200px; height: 200px; margin: 12px 0; border-radius: 8px; background: #fff; }
.recovery-codes { display: grid; grid-template-columns: repeat(2, max-content); gap: 6px 24px; margin: 12px 0; font-size: 15px; }
.invite-result { margin-top: 14px; padding: 12px; border: 1px dashed var(--primary); border-radius: 4px; display: flex; flex-direction: column; gap: 6px; align-items: flex-start; }

.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th { text-align: left; color: var(--text-secondary); font-weight: 600; padding: 6px; border-bottom: 1px solid var(--divider); }
.table td { padding: 6px; border-bottom: 1px solid var(--divider); }
.table tr.muted td { opacity: .55; }
.page .card { overflow-x: auto; }

/* ─── Main layout ─── */

.app { display: flex; height: 100vh; height: 100dvh; overflow: hidden; }

.left-panel {
    width: 320px;
    min-width: 260px;
    display: flex;
    flex-direction: column;
    background: var(--left-panel-bg);
    border-right: 1px solid var(--divider);
}

.left-header {
    background: var(--left-header-bg);
    color: #fff;
    padding: 0 6px 0 16px;
    height: 56px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}
.left-header a.icon-btn { color: #fff; }
.app-title { font-size: 20px; font-weight: 600; }
.conn-state { font-size: 11px; opacity: .85; margin-left: 8px; }

.search-bar { padding: 8px 10px; border-bottom: 1px solid var(--divider); }
.search-input { width: 100%; border: none; box-shadow: 0 1px 3px var(--shadow); }
.token-box { padding: 8px 10px; margin: 8px 0; background: var(--surface-variant); border-radius: 4px; user-select: all; }
.code-block { margin: 6px 0 0; padding: 8px 10px; background: var(--surface-variant); border-radius: 4px; font-family: ui-monospace, Consolas, monospace; font-size: 12px; white-space: pre-wrap; word-break: break-all; }
.row-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.bot-head { display: flex; align-items: center; gap: 10px; }
.bot-name { font-weight: 600; }
.card h3 { margin: 14px 0 0; font-size: 14px; }
.card > a.btn { display: inline-block; margin-top: 8px; }
.no-margin { margin: 0 0 10px; }
.list-section { padding: 8px 14px 4px; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; color: var(--text-secondary); }
.list-note { padding: 8px 14px; text-align: center; }
.search-hit .chat-preview { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
mark { background: rgba(255, 196, 0, 0.45); color: inherit; border-radius: 2px; padding: 0 1px; }
.message-row.flash .message-bubble { animation: msg-flash 1.6s ease-out; }
@keyframes msg-flash { 0%, 30% { box-shadow: 0 0 0 3px rgba(255, 196, 0, 0.8); } 100% { box-shadow: 0 0 0 3px transparent; } }

.chat-list { flex: 1; overflow-y: auto; background: var(--background); }
.chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-bottom: 1px solid var(--divider);
    color: inherit;
}
.chat-item:hover { background: var(--surface-variant); text-decoration: none; }
.chat-item.selected { background: rgba(91, 143, 217, 0.22); }
.chat-content { flex: 1; min-width: 0; }
.chat-item-top, .chat-item-bottom { display: flex; align-items: center; gap: 6px; }
.chat-name { flex: 1; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-time { font-size: 11px; color: var(--text-secondary); flex-shrink: 0; }
.chat-preview { flex: 1; font-size: 13px; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-item.unread .chat-preview { color: var(--text-primary); }
.chat-badge { background: var(--primary); color: #fff; border-radius: 10px; min-width: 20px; padding: 0 6px; font-size: 11px; font-weight: 600; text-align: center; line-height: 20px; }
.chat-badge.muted { background: var(--text-secondary); }
.notify-banner { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-secondary); border-bottom: 1px solid var(--border); font-size: 13px; }
.notify-banner .grow { flex: 1; }

.empty-state, .placeholder { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px; padding: 32px; color: var(--text-secondary); text-align: center; }
.placeholder { flex: 1; }
.placeholder-icon { font-size: 44px; opacity: .6; }

.avatar {
    width: 44px;
    height: 44px;
    border-radius: 4px;
    color: #fff;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
    user-select: none;
}
.avatar.small { width: 36px; height: 36px; font-size: 13px; }

.right-panel { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--surface); position: relative; }

.chat-view-header {
    height: 56px;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 0 12px;
    background: var(--right-header-bg);
    border-bottom: 1px solid var(--divider);
    flex-shrink: 0;
}
.chat-view-header-info { display: flex; align-items: center; gap: 10px; cursor: pointer; min-width: 0; }
.chat-view-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-view-sub { font-size: 12px; color: var(--text-secondary); }
.back-btn { display: none; color: var(--text-primary); }

.messages-container { flex: 1; overflow-y: auto; padding: 12px 20px; display: flex; flex-direction: column; gap: 2px; }
.messages-empty { flex: 1; display: flex; align-items: center; justify-content: center; color: var(--text-secondary); }
.load-older { text-align: center; padding: 6px; }
.day-separator { text-align: center; margin: 10px 0 6px; }
.day-separator span { background: rgba(127, 127, 127, .18); color: var(--text-secondary); font-size: 12px; padding: 2px 10px; border-radius: 10px; }

/* ─── Messages ─── */

.message-row { display: flex; }
.message-row.own { justify-content: flex-end; }
.message-row.other { justify-content: flex-start; }

.message-bubble {
    position: relative;
    max-width: min(640px, 75%);
    padding: 6px 12px 4px;
    border-radius: 4px;
    word-wrap: break-word;
    box-shadow: 0 1px 1px var(--shadow);
}
.message-bubble.own { background: var(--message-sent); border-bottom-right-radius: 2px; }
.message-bubble.other { background: var(--message-received); border-bottom-left-radius: 2px; }
.message-bubble.pending { opacity: .7; }
.message-sender { font-size: 12px; font-weight: 600; margin-bottom: 2px; }
.message-content { white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.message-content.muted { font-style: italic; }
.message-content code { font-family: ui-monospace, Consolas, monospace; background: rgba(127, 127, 127, .18); padding: 0 4px; border-radius: 3px; }
.message-content .code-block { background: rgba(127, 127, 127, .15); padding: 8px; border-radius: 4px; overflow-x: auto; white-space: pre; margin: 4px 0; }
.message-content .code-block code { background: none; padding: 0; }
.spoiler { background: var(--text-primary); color: transparent; border-radius: 3px; cursor: pointer; }
.spoiler.shown { background: rgba(127, 127, 127, .2); color: inherit; }

.message-footer { display: flex; align-items: center; justify-content: flex-end; gap: 6px; font-size: 11px; color: var(--text-secondary); margin-top: 2px; flex-wrap: wrap; }
.message-ticks.read { color: var(--primary); }
.message-edited { font-style: italic; }

.message-quote { display: block; border-left: 3px solid var(--reaction); background: rgba(91, 166, 66, .12); border-radius: 2px; padding: 3px 8px; margin-bottom: 4px; color: inherit; }
.message-quote:hover { text-decoration: none; filter: brightness(.97); }
.quote-name { font-size: 12px; font-weight: 700; color: var(--reaction); }
.quote-text { font-size: 12px; opacity: .75; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.message-more {
    position: absolute;
    top: 2px;
    right: -30px;
    width: 26px;
    height: 26px;
    border: none;
    border-radius: 50%;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    opacity: 0;
    font-size: 16px;
}
.message-row.own .message-more { right: auto; left: -30px; }
.message-row:hover .message-more { opacity: 1; }
.message-more:hover { background: var(--surface-variant); }

.message-reactions-inline { display: flex; flex-wrap: wrap; gap: 4px; flex: 1; }
.reaction-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 1px 8px;
    border: 1px solid var(--divider);
    border-radius: 12px;
    background: var(--surface-variant);
    color: var(--text-primary);
    cursor: pointer;
    font: inherit;
    font-size: 13px;
}
.reaction-badge.active { border-color: var(--reaction); background: rgba(91, 166, 66, .2); }
.reaction-count { font-size: 11px; opacity: .75; }

.typing-bar { font-size: 12px; color: var(--text-secondary); padding: 2px 20px 4px; font-style: italic; }

/* Context menu (echat) */
.ctx-menu { position: fixed; z-index: 1001; background: var(--surface-raised); border: 1px solid var(--border); border-radius: 8px; padding: 4px 0; box-shadow: 0 8px 24px rgba(0, 0, 0, .18); max-width: 95vw; }
.ctx-reaction-strip { display: flex; flex-wrap: wrap; gap: 2px; padding: 6px 8px; max-width: 347px; }
.ctx-reaction-btn { width: 35px; height: 35px; border: none; background: transparent; cursor: pointer; font-size: 22px; border-radius: 50%; line-height: 1; }
.ctx-reaction-btn:hover { background: var(--surface-variant); transform: scale(1.15); }
.ctx-reaction-btn.active { background: rgba(91, 166, 66, .18); }
.ctx-divider { border-top: 1px solid var(--divider); margin: 4px 0; }
.ctx-item { padding: 7px 14px; cursor: pointer; display: flex; align-items: center; gap: 9px; user-select: none; }
.ctx-item:hover { background: var(--surface-variant); }
.ctx-icon { width: 18px; text-align: center; }
.ctx-danger { color: var(--error); }

/* ─── Composer ─── */

.composer { flex-shrink: 0; background: var(--right-header-bg); border-top: 1px solid var(--divider); padding-bottom: env(safe-area-inset-bottom, 0px); }
.compose-strip { display: flex; align-items: center; gap: 10px; padding: 6px 12px; border-bottom: 1px solid var(--divider); }
.strip-icon { color: var(--primary); font-size: 18px; }
.strip-body { flex: 1; min-width: 0; font-size: 12px; }
.strip-body b { color: var(--primary); }
.strip-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--text-secondary); }
.message-input-bar { display: flex; align-items: flex-end; gap: 6px; padding: 8px 12px; }
.message-textarea { flex: 1; resize: none; height: 40px; line-height: 21px; overflow-y: hidden; border-radius: 6px; }
.send-btn { width: 40px; height: 40px; border: none; border-radius: 50%; background: var(--primary); color: #fff; font-size: 18px; cursor: pointer; flex-shrink: 0; }
.send-btn:hover { background: var(--primary-dark); }

/* ─── Modals, toasts ─── */

.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .35); z-index: 1000; }
.backdrop.transparent { background: transparent; }
.modal {
    position: fixed;
    z-index: 1001;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(480px, calc(100vw - 24px));
    max-height: calc(100dvh - 24px);
    display: flex;
    flex-direction: column;
    background: var(--surface-raised);
    border-radius: 8px;
    box-shadow: 0 12px 40px rgba(0, 0, 0, .3);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; padding: 12px 12px 8px 18px; }
.modal-body { padding: 4px 18px 18px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.user-search { display: flex; flex-direction: column; gap: 6px; }
.user-results { display: flex; flex-direction: column; max-height: 280px; overflow-y: auto; }
.user-row { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-radius: 4px; cursor: pointer; }
.user-row:hover { background: var(--surface-variant); }
.member-list .user-row { cursor: default; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: rgba(91, 143, 217, .2); border-radius: 12px; padding: 2px 4px 2px 10px; font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.chip button { border: none; background: none; cursor: pointer; color: inherit; }

.toast { position: fixed; z-index: 1100; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--text-primary); color: var(--surface-raised); padding: 10px 16px; border-radius: 6px; cursor: pointer; max-width: calc(100vw - 32px); box-shadow: 0 6px 20px rgba(0, 0, 0, .3); }
.toast.error { background: var(--error); color: #fff; }

/* ─── Attachments ─── */

.hidden-file-input { display: none; }
.icon-btn.small { width: 26px; height: 26px; font-size: 12px; }
.attach-btn { width: 40px; height: 40px; font-size: 18px; flex-shrink: 0; }
.mic-btn { font-size: 17px; }
.send-btn:disabled { opacity: .5; cursor: default; }

.upload-strip { display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 12px 0; max-height: 140px; overflow-y: auto; }
.upload-chip {
    display: flex; align-items: center; gap: 8px; padding: 4px 4px 4px 6px; width: 220px;
    border-radius: 6px; background: var(--surface-raised); border: 1px solid var(--divider);
}
.upload-chip.failed { border-color: var(--error); }
.upload-thumb { width: 36px; height: 36px; object-fit: cover; border-radius: 4px; flex-shrink: 0; }
.upload-icon { width: 36px; height: 36px; display: flex; align-items: center; justify-content: center; font-size: 20px; flex-shrink: 0; }
.upload-body { flex: 1; min-width: 0; }
.upload-name { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.upload-size { font-size: 11px; color: var(--text-secondary); }
.upload-error { font-size: 11px; color: var(--error); }
.upload-progress { height: 4px; border-radius: 2px; background: var(--divider); margin-top: 4px; overflow: hidden; }
.upload-progress > div { height: 100%; background: var(--primary); transition: width .2s; }

.message-input-bar.recording { align-items: center; }
.record-indicator { flex: 1; display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 8px; }
.record-dot { width: 12px; height: 12px; border-radius: 50%; background: var(--error); transition: transform .15s; }
.record-time { font-variant-numeric: tabular-nums; font-weight: 600; }
.record-hint { color: var(--text-secondary); font-size: 13px; }

.right-panel.drop-target::after {
    content: "Отпустите, чтобы прикрепить файлы";
    position: absolute; inset: 8px; z-index: 50; pointer-events: none;
    display: flex; align-items: center; justify-content: center; font-size: 18px; color: var(--primary);
    border: 2px dashed var(--primary); border-radius: 10px; background: color-mix(in srgb, var(--surface) 85%, transparent);
}

.message-bubble.media-only { padding: 3px; }
.message-bubble.media-only .message-footer {
    position: absolute; right: 8px; bottom: 8px; padding: 0 6px; border-radius: 10px;
    background: rgba(0, 0, 0, .45); color: #fff;
}
.message-bubble.media-only .message-footer .message-time,
.message-bubble.media-only .message-footer .message-ticks { color: #fff; }

.media-grid { display: flex; flex-wrap: wrap; gap: 3px; margin: 2px 0 4px; max-width: 320px; }
.media-thumb {
    padding: 0; border: none; border-radius: 4px; overflow: hidden; cursor: zoom-in;
    background: rgba(127, 127, 127, .2); display: block;
}
.media-grid.multi .media-thumb { width: calc(50% - 2px) !important; height: 150px !important; }
.media-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.media-video { display: block; max-width: min(360px, 100%); max-height: 360px; border-radius: 4px; margin: 2px 0 4px; background: #000; }

.voice { --progress: 0; display: flex; align-items: center; gap: 10px; min-width: 220px; padding: 4px 0; }
.voice-play {
    width: 40px; height: 40px; border-radius: 50%; border: none; flex-shrink: 0; cursor: pointer;
    background: var(--primary); color: #fff; font-size: 14px;
}
.voice .voice-icon-pause, .voice.playing .voice-icon-play { display: none; }
.voice.playing .voice-icon-pause { display: inline; }
.voice-wave { flex: 1; display: flex; align-items: center; gap: 2px; height: 28px; cursor: pointer; position: relative; }
.voice-wave span { flex: 1; min-height: 3px; border-radius: 1px; background: var(--text-muted); }
.voice-wave span.played { background: var(--primary); }
.voice-time { font-size: 12px; color: var(--text-secondary); font-variant-numeric: tabular-nums; min-width: 34px; }

.file-card {
    display: flex; align-items: center; gap: 10px; padding: 6px 8px; margin: 2px 0 4px; min-width: 220px;
    border-radius: 6px; background: rgba(127, 127, 127, .12); color: inherit; text-decoration: none;
}
button.file-card { border: none; font: inherit; text-align: left; cursor: pointer; width: 100%; }
.file-card:hover { background: rgba(127, 127, 127, .2); text-decoration: none; }
.file-card.audio { flex-direction: column; align-items: stretch; }
.file-card audio { width: 100%; height: 36px; }
.file-icon { font-size: 26px; }
.file-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.file-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 500; }
.file-size { font-size: 12px; color: var(--text-secondary); }
.file-download { font-size: 16px; color: var(--primary); }

.lightbox {
    position: fixed; inset: 0; z-index: 1000; background: rgba(0, 0, 0, .9);
    display: flex; align-items: center; justify-content: center; outline: none;
}
.lightbox-img { max-width: 96vw; max-height: calc(100vh - 80px); object-fit: contain; cursor: default; }
.lightbox-bar {
    position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 8px;
    padding: 8px 12px; color: #fff; background: linear-gradient(rgba(0, 0, 0, .6), transparent);
}
.lightbox-bar .icon-btn { color: #fff; }
.lightbox-name { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.lightbox-count { color: #ccc; font-size: 13px; }
.lightbox-nav {
    position: absolute; top: 50%; transform: translateY(-50%); width: 48px; height: 64px; border: none;
    background: rgba(255, 255, 255, .1); color: #fff; font-size: 36px; cursor: pointer; border-radius: 6px;
}
.lightbox-nav:hover { background: rgba(255, 255, 255, .2); }
.lightbox-nav.prev { left: 12px; }
.lightbox-nav.next { right: 12px; }

#blazor-error-ui { display: none; position: fixed; bottom: 0; left: 0; right: 0; padding: 10px 16px; background: #fee2e2; color: #7f1d1d; z-index: 2000; }
#blazor-error-ui .reload { margin-left: 8px; }

/* ─── Calls ─── */

.chat-view-actions { margin-left: auto; display: flex; gap: 2px; color: var(--text-secondary); }
.chat-view-actions .icon-btn:disabled { opacity: .35; cursor: default; background: none; }
.icon { flex-shrink: 0; }

.call-overlay {
    position: fixed; inset: 0; z-index: 1500;
    display: flex; flex-direction: column; align-items: center; justify-content: space-between;
    padding: max(48px, env(safe-area-inset-top)) 16px max(32px, env(safe-area-inset-bottom));
    background: radial-gradient(circle at 50% 30%, #2b3f5c, #0b1220 75%);
    color: #fff; overflow: hidden;
}
.call-overlay.ended .call-status { color: #fca5a5; }
.call-remote { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: #000; }
/* Audio-only: the element still plays the peer's sound, it is just not seen. */
.call-remote.audio-only { width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.call-local {
    position: absolute; z-index: 2; right: 16px; top: max(16px, env(safe-area-inset-top));
    width: 28vw; max-width: 220px; min-width: 96px; aspect-ratio: 3 / 4; object-fit: cover;
    border-radius: 10px; background: #111; box-shadow: 0 6px 24px rgba(0, 0, 0, .5); transform: scaleX(-1);
}
.call-info { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 10px; margin-top: 6vh; text-align: center; }
.call-overlay.with-video .call-info { margin-top: 0; align-self: flex-start; align-items: flex-start; text-shadow: 0 1px 4px rgba(0, 0, 0, .8); }
.avatar.huge { width: 112px; height: 112px; font-size: 40px; border-radius: 50%; }
.avatar.pulse { animation: call-pulse 1.6s ease-out infinite; }
@keyframes call-pulse {
    0% { box-shadow: 0 0 0 0 rgba(255, 255, 255, .35); }
    100% { box-shadow: 0 0 0 28px rgba(255, 255, 255, 0); }
}
.call-name { font-size: 24px; font-weight: 600; max-width: 90vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.call-status { font-size: 15px; color: rgba(255, 255, 255, .75); font-variant-numeric: tabular-nums; }
.call-controls { position: relative; z-index: 1; display: flex; gap: 22px; justify-content: center; flex-wrap: wrap; }
.call-btn {
    width: 64px; height: 64px; border-radius: 50%; border: none; cursor: pointer;
    display: inline-flex; align-items: center; justify-content: center;
    background: rgba(255, 255, 255, .18); color: #fff; backdrop-filter: blur(6px);
    transition: transform .1s, background .15s;
}
.call-btn:hover { background: rgba(255, 255, 255, .28); }
.call-btn:active { transform: scale(.94); }
.call-btn.off { background: #fff; color: #1e293b; }
.call-btn.accept { background: #22c55e; }
.call-btn.accept:hover { background: #16a34a; }
.call-btn.decline { background: #ef4444; }
.call-btn.decline:hover { background: #dc2626; }

/* Group calls: tiles laid out by participant count, filled by rchat-groupcall.js. */
.call-overlay.group-call { justify-content: flex-start; gap: 14px; padding-top: max(20px, env(safe-area-inset-top)); }
.gc-head { display: flex; flex-direction: column; align-items: center; gap: 4px; }
.gc-grid {
    flex: 1; width: 100%; max-width: 1200px; min-height: 0;
    display: grid; gap: 10px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr)); grid-auto-rows: minmax(140px, 1fr);
    align-content: center; overflow-y: auto;
}
.gc-grid[data-count="1"] { grid-template-columns: minmax(0, 720px); justify-content: center; }
.gc-grid[data-count="2"] { grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.gc-tile {
    position: relative; border-radius: 14px; overflow: hidden; background: rgba(255, 255, 255, .08);
    display: flex; align-items: center; justify-content: center; min-height: 140px;
    outline: 3px solid transparent; outline-offset: -3px; transition: outline-color .15s;
}
.gc-tile.speaking { outline-color: #22c55e; }
.gc-tile video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; display: none; background: #000; }
.gc-tile.with-video video { display: block; }
.gc-tile.local video { transform: scaleX(-1); }
.gc-avatar {
    width: 84px; height: 84px; border-radius: 50%; background: var(--primary-dark); color: #fff;
    display: flex; align-items: center; justify-content: center; font-size: 32px; font-weight: 600;
}
.gc-tile.with-video .gc-avatar { display: none; }
.gc-name {
    position: absolute; left: 8px; bottom: 8px; max-width: calc(100% - 16px); padding: 3px 8px; border-radius: 8px;
    background: rgba(0, 0, 0, .55); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    display: flex; gap: 4px; align-items: center;
}
.group-call-banner {
    display: flex; align-items: center; gap: 10px; padding: 8px 14px;
    background: color-mix(in srgb, #22c55e 18%, var(--surface-raised)); border-bottom: 1px solid var(--border); color: var(--text-primary);
}
.group-call-banner.error { background: color-mix(in srgb, #ef4444 15%, var(--surface-raised)); }
.group-call-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 14px; }

.call-record {
    display: flex; align-items: center; gap: 10px; padding: 2px 4px 2px 0; min-width: 190px;
    background: none; border: none; color: inherit; font: inherit; text-align: left; cursor: pointer;
}
.call-record:disabled { cursor: default; }
.call-record-icon {
    width: 36px; height: 36px; border-radius: 50%; flex-shrink: 0;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--success); color: #fff;
}
.call-record.missed .call-record-icon { background: var(--error); }
.call-record-title { display: block; font-weight: 600; }
.call-record.missed .call-record-title { color: var(--error); }
.call-record-sub { display: block; font-size: 12px; color: var(--text-secondary); }

/* ─── Mobile: one panel at a time ─── */

@media (max-width: 768px) {
    .left-panel { width: 100%; min-width: 0; border-right: none; }
    .app.has-chat .left-panel { display: none; }
    .app.no-chat .right-panel { display: none; }
    .back-btn { display: inline-flex; }
    .messages-container { padding: 10px; }
    .message-bubble { max-width: 85%; }
    .message-more { display: none; }
}

/* Avatar colours (echat palette); "-text" variants colour sender names. */
.avatar-color-0 { background: #5b8fd9; } .avatar-color-0-text { color: #5b8fd9; }
.avatar-color-1 { background: #e07a5f; } .avatar-color-1-text { color: #e07a5f; }
.avatar-color-2 { background: #81b29a; } .avatar-color-2-text { color: #4f8a6d; }
.avatar-color-3 { background: #f2cc8f; color: #333; } .avatar-color-3-text { color: #c08a2e; }
.avatar-color-4 { background: #9b5de5; } .avatar-color-4-text { color: #9b5de5; }
.avatar-color-5 { background: #00bbf9; } .avatar-color-5-text { color: #0096c7; }
.avatar-color-6 { background: #f15bb5; } .avatar-color-6-text { color: #d6409f; }
.avatar-color-7 { background: #fee440; color: #333; } .avatar-color-7-text { color: #b59f00; }
.avatar-color-8 { background: #00f5d4; color: #333; } .avatar-color-8-text { color: #00a88f; }
.avatar-color-9 { background: #99c2b2; } .avatar-color-9-text { color: #5f8f7c; }
.avatar-color-10 { background: #d4a373; } .avatar-color-10-text { color: #b07a44; }
.avatar-color-11 { background: #a8dadc; color: #333; } .avatar-color-11-text { color: #4c9a9e; }
.avatar-color-12 { background: #e9c46a; color: #333; } .avatar-color-12-text { color: #b08f2a; }
.avatar-color-13 { background: #2a9d8f; } .avatar-color-13-text { color: #2a9d8f; }
.avatar-color-14 { background: #e76f51; } .avatar-color-14-text { color: #e76f51; }
.avatar-color-15 { background: #606c38; } .avatar-color-15-text { color: #7a8a45; }

/* Secret chats */
.safety-code {
    font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 17px; letter-spacing: .5px; line-height: 1.6;
    display: grid; grid-template-columns: repeat(4, max-content); gap: 2px 14px; margin: 6px 0;
}
