/* Main chat layout — 4 columns */
.chat-layout {
    display: flex;
    height: 100%;
    max-width: 100vw;
    overflow: hidden;
}

/* Channel sidebar */
.channel-sidebar {
    width: 240px;
    background-color: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    border-right: 1px solid var(--border);
    overflow: hidden;
}

.channel-sidebar-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
}

.channel-sidebar-header h3 {
    font-size: 16px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.channel-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

/* Channel items */
.channel-item {
    padding: 6px 12px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 4px;
    transition: background-color 0.15s, color 0.15s;
    min-width: 0;
}

.channel-item:hover {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
}

.channel-item.active {
    background-color: var(--bg-tertiary);
    color: var(--text-primary);
    font-weight: 500;
}


.channel-name-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Unread channel indicator */
.channel-unread .channel-name-text {
    color: var(--text-primary);
    font-weight: 600;
}
.channel-unread-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
    flex-shrink: 0;
}

.channel-mute-btn {
    margin-left: auto;
    border: none;
    background: none;
    font-size: 16px;
    cursor: pointer;
    padding: 2px 4px;
    border-radius: 4px;
    opacity: 0;
    transition: opacity 0.15s;
    flex-shrink: 0;
    line-height: 1;
}
.channel-item:hover .channel-mute-btn { opacity: 0.5; }
.channel-mute-btn:hover { opacity: 1 !important; background: var(--bg-tertiary); }
.channel-mute-btn.muted { opacity: 0.5; }
.channel-item:hover .channel-mute-btn.muted { opacity: 0.8; }
.channel-mute-btn.muted:hover { opacity: 1 !important; }

/* Channel context menu */
.channel-ctx-menu {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px;
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 1000;
    min-width: 160px;
}
.channel-ctx-item {
    display: block;
    width: 100%;
    padding: 6px 10px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
}
.channel-ctx-item:hover { background: var(--bg-tertiary); }

.channel-hash {
    color: var(--text-muted);
    font-size: 18px;
    font-weight: 400;
    margin-right: 2px;
}

/* Categories */
.channel-category {
    margin-top: 12px;
}

.channel-category:first-child {
    margin-top: 0;
}

.channel-category-name {
    display: flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    padding: 2px 8px 4px;
    cursor: pointer;
    user-select: none;
    border-radius: 4px;
    transition: color 0.12s, background 0.12s;
}

.channel-category-name:hover {
    color: var(--text-normal);
    background: rgba(255,255,255,0.05);
}

.category-toggle {
    background: none;
    border: none;
    cursor: pointer;
    color: inherit;
    font-size: 11px;
    padding: 0;
    line-height: 1;
    flex-shrink: 0;
    width: 14px;
    text-align: center;
}

/* When collapsed: hide channels that don't need to be seen */
.channel-category.collapsed .channel-category-channels .channel-item:not(.leaked) {
    display: none;
}

/* Leaked channels (unread or active) show in collapsed category with subtle style */
.channel-category.collapsed .channel-category-channels .channel-item.leaked {
    opacity: 0.9;
}

.channel-category-channels {
    display: flex;
    flex-direction: column;
}

/* Chat area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background-color: var(--bg-secondary);
    min-width: 0;
}

.chat-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    font-weight: 600;
    font-size: 16px;
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.chat-header-channel-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

.chat-header-spacer {
    flex: 1;
}

/* Desktop: hide mobile search button */
.mobile-search-btn {
    display: none !important;
}

.chat-search {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
    width: 200px;
    outline: none;
}

.chat-search:focus {
    border-color: var(--accent);
}

.chat-messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    overflow-anchor: auto; /* browsers handle smooth scroll anchor on desktop */
}

/* iOS WebKit: disable overflow-anchor because its implementation is unreliable.
   JS adds .ios-scroll-anchor-off to the container on iOS. */
.chat-messages.ios-scroll-anchor-off {
    overflow-anchor: none;
}

.chat-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    font-size: 16px;
}

.chat-input-area {
    padding: 12px 16px;
    flex-shrink: 0;
    position: relative;
}

.chat-input {
    width: 100%;
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background-color: var(--bg-input);
    color: var(--text-primary);
    font-size: 16px;
    outline: none;
    resize: none;
    font-family: inherit;
    line-height: 1.4;
    min-height: 40px;
    max-height: 200px;
    overflow-y: auto;
}

.chat-input::placeholder {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-input:focus {
    box-shadow: 0 0 0 2px var(--accent);
}

.chat-input:disabled {
    opacity: 0.5;
}

/* Members sidebar */
.members-sidebar {
    width: 240px;
    background-color: var(--bg-secondary);
    border-left: 1px solid var(--border);
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
}

.members-header {
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
}

.members-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.member-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.member-item:hover {
    background-color: var(--bg-tertiary);
}

.member-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    flex-shrink: 0;
}

.member-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.member-name {
    font-size: 14px;
    color: var(--text-primary);
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-username {
    font-size: 11px;
    color: var(--text-muted);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.member-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-online { background-color: var(--success); }
.status-dnd { background-color: var(--danger); }
.status-offline { background-color: var(--text-muted); }

/* Server sidebar buttons */
.server-icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    font-size: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 4px;
}

.server-icon-btn:hover {
    background: var(--accent);
    color: #fff;
}

/* Active server icon */
.server-icon.active {
    border-radius: 16px;
    background-color: var(--accent);
    box-shadow: 0 0 0 2px var(--accent);
}

/* Messages */
.message {
    padding: 4px 16px;
    transition: background-color 0.1s;
}

.message:hover {
    background-color: var(--bg-tertiary);
}

.message-deleted {
    opacity: 0.5;
}

.message-body {
    display: flex;
    gap: 12px;
    max-width: 100%;
    overflow: hidden;
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background-color: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
    flex-shrink: 0;
    overflow: hidden;
}

.message-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.message-main {
    flex: 1;
    min-width: 0;
}

.message-header {
    display: flex;
    align-items: baseline;
    gap: 8px;
    margin-bottom: 2px;
}

.message-author {
    font-weight: 600;
    font-size: 14px;
}

.message-time {
    font-size: 11px;
    color: var(--text-muted);
}

.message-content {
    font-size: 15px;
    line-height: 1.4;
    word-wrap: break-word;
    white-space: pre-wrap;
}

.message-edited {
    font-size: 11px;
    color: var(--text-muted);
}

.message-reply {
    margin-left: 52px;
    padding: 4px 8px;
    margin-bottom: 4px;
    border-left: 2px solid var(--accent);
    font-size: 13px;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 4px;
    transition: background-color 0.15s;
}

.message-reply:hover {
    background: var(--bg-tertiary);
}

.message-highlight {
    animation: msg-flash 2s ease-out;
}

@keyframes msg-flash {
    0%, 20% { background: rgba(88, 101, 242, 0.2); }
    100% { background: transparent; }
}

.message-reply-text {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    display: block;
}

.message-sentinel {
    height: 1px;
}

.vs-spacer-top,
.vs-spacer-bottom {
    width: 100%;
}

/* Typing indicator */
.typing-indicator {
    padding: 0 16px;
    font-size: 12px;
    color: var(--text-muted);
    min-height: 20px;
}

/* Reactions */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-left: 52px;
    margin-top: 4px;
}

.reaction-btn {
    padding: 2px 8px;
    border: 1px solid var(--border);
    border-radius: 12px;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: background-color 0.15s;
}

.reaction-btn:hover {
    background: var(--bg-tertiary);
}

.reaction-own {
    border-color: var(--accent);
    background: rgba(88, 101, 242, 0.1);
}

/* Hover menu */
.message-hover-menu {
    position: absolute;
    top: -12px;
    right: 16px;
    display: none;
    gap: 2px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    padding: 2px;
    box-shadow: 0 2px 8px var(--shadow);
}

.message {
    position: relative;
}

.message:hover .message-hover-menu {
    display: flex;
}

.hover-btn {
    padding: 4px 8px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 3px;
    font-size: 14px;
}

.hover-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Mobile long-press message menu */
.mobile-msg-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 3000;
    display: flex;
    align-items: flex-end;
    justify-content: center;
}

.mobile-msg-menu {
    background: var(--bg-secondary);
    border-radius: 16px 16px 0 0;
    width: 100%;
    max-width: 480px;
    padding: 8px 0;
    padding-bottom: env(safe-area-inset-bottom, 8px);
    -webkit-user-select: none;
    user-select: none;
}

.mobile-msg-action {
    display: flex;
    align-items: center;
    gap: 14px;
    width: 100%;
    padding: 14px 20px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 15px;
    cursor: pointer;
    text-align: left;
}

.mobile-msg-action:active {
    background: var(--bg-tertiary);
}

.mobile-msg-action-icon {
    font-size: 20px;
    width: 28px;
    text-align: center;
    flex-shrink: 0;
}

.mobile-msg-action-danger {
    color: var(--danger);
}

/* Pin badge */
.message-pin-badge {
    font-size: 10px;
    background: var(--accent);
    color: #fff;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 4px;
}

/* Reply preview above input */
.reply-preview {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    border-radius: 4px 4px 0 0;
    font-size: 13px;
    color: var(--text-secondary);
}

.reply-preview-text {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.reply-preview-close {
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 18px;
}

/* Text formatting */
.message-content strong { font-weight: 700; }
.message-content em { font-style: italic; }
.message-content del { text-decoration: line-through; color: var(--text-muted); }

.msg-spoiler {
    background: var(--text-primary);
    color: transparent;
    border-radius: 3px;
    padding: 0 4px;
    cursor: pointer;
    transition: all 0.2s;
    user-select: none;
}
.msg-spoiler.revealed {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.server-tooltip-muted {
    margin-top: 6px;
    padding-top: 6px;
    border-top: 1px solid var(--border);
    color: var(--danger);
    font-size: 12px;
}

.server-mute-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 16px;
    padding: 4px 6px;
    border-radius: 4px;
}

.server-mute-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.server-mute-btn.muted {
    color: var(--danger);
}

.msg-link {
    color: var(--accent);
    text-decoration: none;
    word-break: break-all;
}

.msg-link:hover {
    text-decoration: underline;
}

.msg-code {
    background: var(--bg-tertiary);
    padding: 1px 6px;
    border-radius: 3px;
    font-family: monospace;
    font-size: 13px;
}

.msg-code-block {
    background: var(--bg-tertiary);
    padding: 8px 12px;
    border-radius: 6px;
    font-family: monospace;
    font-size: 13px;
    overflow-x: auto;
    margin: 4px 0;
    white-space: pre-wrap;
}

.msg-quote {
    border-left: 3px solid var(--accent);
    padding-left: 10px;
    margin: 4px 0;
    color: var(--text-secondary);
}

/* Attachment spoiler */
.attachment-spoiler-wrap {
    position: relative;
    cursor: pointer;
    overflow: hidden;
    border-radius: 8px;
    display: inline-block;
}
.attachment-spoiler-wrap:not(.revealed) img,
.attachment-spoiler-wrap:not(.revealed) video {
    filter: blur(16px);
    transform: scale(1.1);
}
.attachment-spoiler-wrap:not(.revealed) .cvp-controls {
    display: none;
}
.attachment-spoiler-wrap:not(.revealed) .cvp-play-overlay {
    display: none;
}
.attachment-spoiler-wrap:not(.revealed) .custom-video-player {
    pointer-events: none;
}
.attachment-spoiler-label {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0,0,0,0.7);
    color: #fff;
    padding: 6px 16px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    z-index: 2;
    pointer-events: none;
}
.attachment-spoiler-wrap.revealed .attachment-spoiler-label {
    display: none;
}

/* File preview spoiler toggle button */
.file-preview-spoiler {
    position: absolute;
    bottom: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
}
.file-preview-item:hover .file-preview-spoiler { opacity: 1; }
.file-preview-spoiler.active {
    opacity: 1;
    background: var(--danger);
}

/* Reconnect banner */
.ws-reconnect-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    background-color: var(--danger);
    color: #fff;
    text-align: center;
    padding: 6px;
    font-size: 13px;
    z-index: 9999;
}

/* ===== File upload & attachments ===== */

/* Input row with buttons */
.input-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

.input-row .chat-input {
    flex: 1;
}

.input-action-btn {
    width: 36px;
    height: 36px;
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.15s, color 0.15s;
}

.input-action-btn:hover {
    background: var(--accent);
    color: #fff;
}

.voice-send-btn {
    transition: background-color 0.2s, color 0.2s;
}

.voice-send-btn.send-mode {
    background: var(--accent);
    color: #fff;
}

.voice-send-btn.recording {
    background: var(--danger);
    color: #fff;
    animation: pulse 1s infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.6; }
}

/* File preview bar */
/* Upload progress UI */
.upload-progress-container {
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.upload-progress-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border: 1px solid var(--border);
    border-radius: 8px;
    animation: upload-fade-in 0.2s ease;
}

@keyframes upload-fade-in {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.upload-progress-thumb {
    width: 40px;
    height: 40px;
    border-radius: 6px;
    overflow: hidden;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
}

.upload-progress-thumb img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.upload-progress-info {
    flex: 1;
    min-width: 0;
}

.upload-progress-name {
    font-size: 12px;
    font-weight: 500;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.upload-progress-bar {
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.upload-progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent);
    border-radius: 2px;
    transition: width 0.2s ease;
}

.upload-progress-status {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.upload-progress-cancel {
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
    padding: 4px;
    border-radius: 50%;
    width: 28px;
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background-color 0.15s, color 0.15s;
}

.upload-progress-cancel:hover {
    background: var(--danger);
    color: #fff;
}

.file-preview {
    display: flex;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-tertiary);
    border-radius: 8px 8px 0 0;
    overflow-x: auto;
    flex-wrap: nowrap;
}

.file-preview-item {
    position: relative;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 8px;
    background: var(--bg-secondary);
    border-radius: 6px;
    flex-shrink: 0;
    max-width: 160px;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

.file-preview-item img {
    -webkit-user-drag: none;
    user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: none;
}

/* Charging state — fills during hold so user sees drag is about to activate */
.file-preview-item.drag-charging {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    animation: file-charge 0.3s ease-out;
}

@keyframes file-charge {
    from { outline-color: transparent; transform: scale(1); }
    to   { outline-color: var(--accent); transform: scale(0.95); }
}

/* Lifted ghost during drag — tilted card with strong shadow */
.drag-ghost-lifted {
    transform: scale(1.08) rotate(-3deg);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.45);
    opacity: 0.95;
    transition: none;
    outline: 2px solid var(--accent);
}

/* Original item while its ghost is being dragged */
.file-preview-item.dragging {
    opacity: 0.25;
}

.file-preview-item.spoiler-active {
    outline: 2px solid var(--warning);
    outline-offset: -2px;
}

.file-preview-item.spoiler-active .file-preview-thumb {
    filter: blur(16px);
}

.file-preview-item.spoiler-active .file-preview-icon::after {
    content: ' 👁';
}

.file-preview-thumb {
    width: 60px;
    height: 60px;
    object-fit: cover;
    border-radius: 4px;
}

.file-preview-icon {
    width: 40px;
    height: 40px;
    background: var(--bg-primary);
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-muted);
    flex-shrink: 0;
}

.file-preview-name {
    font-size: 12px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 80px;
}

.file-preview-remove {
    position: absolute;
    top: -4px;
    right: -4px;
    width: 18px;
    height: 18px;
    border: none;
    background: var(--danger);
    color: #fff;
    border-radius: 50%;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
}

/* Mobile file action popup */
.file-action-popup {
    position: fixed;
    background: rgba(30, 33, 48, 0.55);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 6px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    overflow: hidden;
    z-index: 200;
}

.file-action-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 0;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 14px;
    cursor: pointer;
    white-space: nowrap;
}

.file-action-btn:active {
    background: var(--bg-tertiary);
}

.file-action-btn.file-action-remove {
    color: var(--danger);
}

/* Drag & drop overlay */
.chat-area.drag-over::after {
    content: 'Drop files here';
    position: absolute;
    inset: 0;
    background: rgba(88, 101, 242, 0.15);
    border: 2px dashed var(--accent);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: var(--accent);
    z-index: 100;
    pointer-events: none;
}

.chat-area {
    position: relative;
}

/* Message attachments */
.message-images {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.message-image {
    max-width: 300px;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
    object-fit: cover;
    transition: opacity 0.15s;
}

.message-image:hover {
    opacity: 0.85;
}

/* Video player in messages */
.message-video-wrap {
    margin-top: 6px;
    max-width: 450px;
    border-radius: 8px;
    overflow: hidden;
    background: #000;
}

.message-video {
    width: 100%;
    max-height: 400px;
    display: block;
    object-fit: contain;
}

/* Custom video player */
.custom-video-player {
    margin-top: 6px;
    max-width: 450px;
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-primary);
    border: 1px solid var(--border);
}

.cvp-video-container {
    position: relative;
    cursor: pointer;
}

.cvp-video {
    width: 100%;
    max-height: 400px;
    display: block;
    object-fit: contain;
}

.cvp-play-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0,0,0,0.3);
    transition: opacity 0.2s;
}

.cvp-play-big {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding-left: 4px;
    transition: transform 0.15s;
}

.cvp-play-overlay:hover .cvp-play-big {
    transform: scale(1.1);
}

.cvp-controls {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 6px 10px;
    background: var(--bg-secondary);
}

.cvp-btn {
    border: none;
    background: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    padding: 2px 4px;
    border-radius: 4px;
    text-decoration: none;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 28px;
    flex-shrink: 0;
}

.cvp-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.cvp-progress {
    flex: 1;
    height: 6px;
    background: var(--bg-tertiary);
    border-radius: 3px;
    cursor: pointer;
    overflow: hidden;
}

.cvp-progress:hover {
    height: 8px;
}

.cvp-progress-fill {
    height: 100%;
    background: var(--accent);
    border-radius: 3px;
    transition: width 0.15s linear;
    pointer-events: none;
}

.cvp-time {
    font-size: 11px;
    color: var(--text-muted);
    min-width: 28px;
    text-align: center;
    font-variant-numeric: tabular-nums;
}

.cvp-volume {
    width: 60px;
    height: 4px;
    cursor: pointer;
    accent-color: var(--accent);
}

.cvp-volume-btn {
    font-size: 16px;
}

/* Unsupported video format card */
.message-video-unsupported {
    margin-top: 6px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.message-video-unsupported-icon {
    font-size: 32px;
    flex-shrink: 0;
}

.message-video-unsupported-info {
    flex: 1;
    min-width: 0;
}

.message-video-unsupported-info .message-file-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Video transcoding in progress */
.message-video-processing {
    margin-top: 6px;
    max-width: 400px;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border);
}

.message-video-processing-icon {
    font-size: 28px;
    animation: spin 2s linear infinite;
}

@keyframes spin {
    100% { transform: rotate(360deg); }
}

.message-video-processing-info {
    flex: 1;
    min-width: 0;
}

.message-video-info {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 10px;
    background: var(--bg-primary);
    font-size: 12px;
}

.message-video-info .message-file-name {
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-video-download {
    color: var(--text-muted);
    text-decoration: none;
    font-size: 16px;
}

.message-video-download:hover {
    color: var(--accent);
}

/* Audio player in messages */
/* Link preview cards */
/* Invite preview card */
.invite-preview-card {
    display: flex;
    align-items: center;
    gap: 12px;
    max-width: 400px;
    margin-top: 6px;
    padding: 12px;
    background: var(--bg-primary);
    border-radius: 8px;
    border-left: 3px solid var(--success, #3ba55d);
}

.invite-preview-icon {
    width: 48px;
    height: 48px;
    border-radius: 12px;
    object-fit: cover;
    flex-shrink: 0;
}

.invite-preview-icon-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: #fff;
    font-size: 20px;
    font-weight: 600;
}

.invite-preview-body {
    flex: 1;
    min-width: 0;
}

.invite-preview-label {
    font-size: 10px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.invite-preview-name {
    font-size: 15px;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.invite-preview-meta {
    font-size: 12px;
    color: var(--text-muted);
}

.invite-preview-join {
    flex-shrink: 0;
    padding: 6px 16px;
    font-size: 13px;
}

.invite-preview-invalid {
    border-left-color: var(--danger);
    opacity: 0.7;
}

.invite-preview-invalid .invite-preview-name {
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 400;
}

.link-preview-card {
    display: flex;
    flex-direction: column;
    max-width: 400px;
    margin-top: 6px;
    background: var(--bg-primary);
    border-radius: 8px;
    border-left: 3px solid var(--accent);
    overflow: hidden;
    text-decoration: none;
    color: var(--text-primary);
    transition: background-color 0.15s;
}

.link-preview-card:hover {
    background: var(--bg-tertiary);
}

.link-preview-image {
    width: 100%;
    max-height: 200px;
    overflow: hidden;
}

.link-preview-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.link-preview-body {
    padding: 8px 12px;
    min-width: 0;
    flex: 1;
}

.link-preview-site {
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.3px;
    margin-bottom: 2px;
}

.link-preview-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.link-preview-desc {
    font-size: 12px;
    color: var(--text-secondary);
    margin-top: 4px;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.link-preview-loading {
    margin-top: 6px;
    font-size: 12px;
    color: var(--text-muted);
    display: flex;
    align-items: center;
    gap: 6px;
}

.link-preview-loading-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-muted);
    animation: lp-pulse 1.2s ease-in-out infinite;
}

@keyframes lp-pulse {
    0%, 100% { opacity: 0.3; }
    50% { opacity: 1; }
}

.message-audio-wrap {
    margin-top: 6px;
    max-width: 400px;
    background: var(--bg-primary);
    border-radius: 8px;
    padding: 8px 12px;
}

.message-audio-name {
    font-size: 12px;
    margin-bottom: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-audio {
    width: 100%;
    height: 32px;
}

.message-files {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-top: 6px;
}

.message-file {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border-radius: 6px;
    text-decoration: none;
    color: var(--text-primary);
    max-width: 400px;
    transition: background-color 0.15s;
}

.message-file:hover {
    background: var(--bg-tertiary);
    text-decoration: none;
}

.message-file-icon {
    width: 36px;
    height: 36px;
    background: var(--bg-tertiary);
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 10px;
    font-weight: 700;
    color: var(--accent);
    flex-shrink: 0;
}

.message-file-info {
    min-width: 0;
}

.message-file-name {
    font-size: 14px;
    font-weight: 500;
    color: var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.message-file-size {
    font-size: 12px;
    color: var(--text-muted);
}

/* Voice player */
.voice-player {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    background: var(--bg-primary);
    border-radius: 20px;
    max-width: 300px;
    margin-top: 6px;
}

.voice-play-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--accent);
    color: #fff;
    border-radius: 50%;
    cursor: pointer;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.voice-play-btn:hover {
    background: var(--accent-hover);
}

.voice-waveform {
    flex: 1;
    height: 8px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    overflow: hidden;
    cursor: pointer;
    position: relative;
}

.voice-waveform:hover {
    height: 10px;
}

.voice-progress {
    height: 100%;
    background: var(--accent);
    border-radius: 4px;
    transition: width 0.1s linear;
    pointer-events: none;
}

/* Recording timer — floats above voice button */
.recording-timer {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 50%;
    transform: translateX(-50%) translateY(8px);
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 4px 12px;
    display: flex;
    align-items: center;
    gap: 6px;
    white-space: nowrap;
    box-shadow: 0 4px 12px var(--shadow);
    opacity: 0;
    transition: opacity 0.3s ease, transform 0.3s ease;
    pointer-events: none;
    z-index: 10;
}

.recording-timer-visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.recording-timer-hiding {
    opacity: 0;
    transform: translateX(-50%) translateY(8px);
}

.recording-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--danger);
    animation: rec-pulse 1s ease-in-out infinite;
}

@keyframes rec-pulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.3; }
}

.recording-time {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    font-variant-numeric: tabular-nums;
}

/* Video quality picker */
.quality-options {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.quality-option {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    transition: background-color 0.15s;
    border: 1px solid transparent;
}

.quality-option:hover {
    background: var(--bg-tertiary);
}

.quality-option-selected {
    background: var(--bg-tertiary);
    border-color: var(--accent);
}

.quality-option input[type="radio"] {
    display: none;
}

.quality-label {
    font-size: 15px;
    font-weight: 600;
}

.quality-desc {
    font-size: 11px;
    color: var(--text-muted);
    margin-left: auto;
}

.voice-duration {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    min-width: 32px;
    text-align: right;
}

.voice-volume {
    width: 50px;
    height: 4px;
    cursor: pointer;
    accent-color: var(--accent);
    flex-shrink: 0;
}

.voice-speed-btn {
    border: 1px solid var(--border);
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 8px;
    cursor: pointer;
    flex-shrink: 0;
    min-width: 36px;
    text-align: center;
    transition: background-color 0.15s, color 0.15s;
}

.voice-speed-btn:hover {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* ===== Image Viewer (Lightbox) ===== */
.image-viewer-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 10000;
}

.iv-close {
    position: absolute;
    top: 16px;
    right: 16px;
    width: 40px;
    height: 40px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.iv-close:hover {
    background: rgba(255, 255, 255, 0.2);
}

.iv-prev, .iv-next {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    border: none;
    background: rgba(255, 255, 255, 0.1);
    color: #fff;
    font-size: 24px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.iv-prev { left: 16px; }
.iv-next { right: 16px; }

.iv-prev:hover, .iv-next:hover {
    background: rgba(255, 255, 255, 0.2);
}

.iv-content {
    max-width: 90vw;
    max-height: 80vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.iv-image {
    max-width: 90vw;
    max-height: 80vh;
    object-fit: contain;
    border-radius: 4px;
}

.iv-footer {
    margin-top: 12px;
}

.iv-download {
    color: #fff;
    font-size: 14px;
    opacity: 0.7;
    text-decoration: none;
}

.iv-download:hover {
    opacity: 1;
    text-decoration: underline;
}

/* Send button */
/* Legacy send-btn styles removed — merged into .voice-send-btn */

/* Emoji picker */
.emoji-picker {
    position: fixed;
    z-index: 2000;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 2px;
    box-shadow: 0 8px 24px var(--shadow);
    width: 284px;
    max-height: 300px;
    overflow-y: auto;
}

.message.message-picker-open .message-hover-menu {
    display: flex;
}

/* Full emoji panel (message input) */
.emoji-panel {
    position: fixed;
    z-index: 2000;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 12px;
    width: 340px;
    max-height: 420px;
    display: flex;
    flex-direction: column;
    box-shadow: 0 8px 24px var(--shadow);
    overflow: hidden;
}

.emoji-panel-header {
    padding: 10px 12px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.emoji-panel-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}

.emoji-panel-tab {
    flex: 1;
    padding: 8px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: color 0.15s, border-color 0.15s;
    border-bottom: 2px solid transparent;
}

.emoji-panel-tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.emoji-panel-tab:hover {
    color: var(--text-primary);
}

.emoji-panel-search {
    margin: 8px;
    padding: 6px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 13px;
    flex-shrink: 0;
}

.emoji-panel-search:focus {
    border-color: var(--accent);
    outline: none;
}

.emoji-panel-catbar {
    display: flex;
    gap: 2px;
    padding: 0 8px 6px;
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
    position: relative;
    z-index: 1;
    background: var(--bg-secondary);
}

.emoji-panel-cat-btn {
    border: none;
    background: none;
    font-size: 16px;
    padding: 4px;
    cursor: pointer;
    border-radius: 4px;
    opacity: 0.6;
    transition: opacity 0.15s, background 0.15s;
}

.emoji-panel-cat-btn:hover {
    opacity: 1;
    background: var(--bg-tertiary);
}

.emoji-panel-grid {
    flex: 1;
    overflow-y: auto;
    padding: 0 8px 4px;
}

.emoji-panel-cat-header {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    color: var(--text-muted);
    letter-spacing: 0.5px;
    padding: 8px 0 4px;
    position: sticky;
    top: 0;
    background: var(--bg-secondary);
    z-index: 1;
}

.emoji-panel-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1px;
}

.emoji-panel-stickers {
    flex: 1;
    overflow-y: auto;
}

.emoji-panel-gifs {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
}

.gif-favorites-row {
    scrollbar-width: none;
    -ms-overflow-style: none;
}

.gif-favorites-row::-webkit-scrollbar {
    display: none;
}

.emoji-input-btn.active {
    background: var(--accent);
    color: #fff;
}

/* Sticker picker */
.sticker-pack-bar {
    display: flex;
    gap: 2px;
    padding: 4px 8px;
    border-bottom: 1px solid var(--border);
    overflow-x: auto;
    flex-shrink: 0;
}

.sticker-pack-btn {
    border: none;
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    font-size: 11px;
    font-weight: 700;
    padding: 4px 8px;
    border-radius: 4px;
    cursor: pointer;
    white-space: nowrap;
    flex-shrink: 0;
}

.sticker-pack-btn.active {
    background: var(--accent);
    color: #fff;
}

.sticker-pack-btn:hover {
    background: var(--accent-hover);
    color: #fff;
}

.sticker-pack-add {
    background: transparent;
    border: 1px dashed var(--border);
    color: var(--text-muted);
}

.sticker-grid {
    flex: 1;
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 8px;
    overflow-y: auto;
    max-height: 240px;
}

.sticker-item {
    aspect-ratio: 1;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background-color 0.15s, transform 0.1s;
    padding: 4px;
}

.sticker-item:hover {
    background: var(--bg-tertiary);
    transform: scale(1.1);
}

.sticker-item img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

.sticker-upload-area {
    padding: 6px 8px;
    border-top: 1px solid var(--border);
    text-align: center;
    flex-shrink: 0;
}

.sticker-upload-btn {
    font-size: 11px;
    padding: 4px 10px;
}

/* Sticker in chat message */
.message-sticker {
    margin-top: 4px;
}

.message-sticker img {
    display: block;
    border-radius: 4px;
}

.emoji-picker-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    font-size: 20px;
    cursor: pointer;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

.emoji-picker-btn:hover {
    background: var(--bg-tertiary);
}

/* Inline edit */
.inline-edit-input {
    width: 100%;
    padding: 8px;
    border: 1px solid var(--accent);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 16px; /* ≥16px prevents iOS Safari from auto-zooming on focus */
    font-family: inherit;
    resize: vertical;
    min-height: 40px;
    box-sizing: border-box;
}

.inline-edit-actions {
    display: flex;
    gap: 6px;
    margin-top: 4px;
}

.inline-edit-actions button {
    padding: 4px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.inline-edit-save {
    background: var(--accent);
    color: #fff;
}

.inline-edit-cancel {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.inline-edit-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
    display: block;
}

.message-editing .message-hover-menu {
    display: none !important;
}

/* Attachment editor in inline edit */
.edit-attachments {
    margin-top: 8px;
    border-top: 1px solid var(--border);
    padding-top: 8px;
}

.edit-attachments-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 8px;
}

.edit-att-item {
    position: relative;
    width: 80px;
    height: 80px;
    border-radius: 6px;
    overflow: hidden;
    border: 1px solid var(--border);
    cursor: grab;
    transition: opacity 0.2s, border-color 0.2s;
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    touch-action: none;
}

.edit-att-item img {
    -webkit-user-drag: none;
    -webkit-touch-callout: none;
    pointer-events: none;
}

.edit-att-item:active {
    cursor: grabbing;
}

.edit-att-item.dragging {
    opacity: 0.25;
}

.edit-att-item.drag-charging {
    outline: 2px solid var(--accent);
    outline-offset: -2px;
    animation: file-charge 0.3s ease-out;
}

/* Spoiler indicator (matches .file-preview-item.spoiler-active) */
.edit-att-item.spoiler-active {
    outline: 2px solid var(--warning);
    outline-offset: -2px;
}

.edit-att-item.spoiler-active .edit-att-thumb {
    filter: blur(12px);
}

.edit-att-item.spoiler-active .edit-att-icon::after {
    content: ' 👁';
}

.edit-att-item.removed {
    opacity: 0.3;
    border-color: var(--danger);
}

.edit-att-thumb {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.edit-att-icon {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg-tertiary);
    font-size: 11px;
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
}

.edit-att-remove {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
}

.edit-att-item:hover .edit-att-remove {
    opacity: 1;
}

.edit-att-spoiler {
    position: absolute;
    bottom: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    border-radius: 50%;
    border: none;
    background: rgba(0,0,0,0.6);
    color: #fff;
    font-size: 11px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
}
.edit-att-item:hover .edit-att-spoiler { opacity: 1; }
.edit-att-spoiler.active {
    opacity: 1;
    background: var(--danger);
}

.edit-att-add {
    background: var(--bg-tertiary);
    color: var(--text-secondary);
    border: 1px dashed var(--border);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background-color 0.15s, color 0.15s, border-color 0.15s;
}

.edit-att-add:hover {
    background: var(--bg-secondary);
    color: var(--accent);
    border-color: var(--accent);
}

.edit-att-add-icon {
    font-size: 36px;
    font-weight: 300;
    line-height: 1;
    pointer-events: none;
}

/* Collapsible members */
.chat-header-btn {
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    padding: 4px 8px;
    border-radius: 4px;
}

.chat-header-btn:hover {
    color: var(--text-primary);
    background: var(--bg-tertiary);
}

.chat-layout.members-hidden .members-sidebar {
    display: none;
}

/* Typing indicator in members */
.member-typing .member-name::after {
    content: ' ...';
    animation: typing-dots 1.4s infinite;
}

@keyframes typing-dots {
    0%, 20% { content: ' .'; }
    40% { content: ' ..'; }
    60%, 100% { content: ' ...'; }
}

.typing-indicator {
    font-size: 12px;
    color: var(--text-muted);
    padding: 0 16px;
    min-height: 20px;
}

/* Polls */
.poll-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 16px;
    margin: 8px 52px 8px 52px;
    max-width: 400px;
}

.poll-question {
    font-weight: 700;
    font-size: 15px;
    margin-bottom: 12px;
}

.poll-option {
    position: relative;
    padding: 8px 12px;
    margin-bottom: 6px;
    border-radius: 6px;
    cursor: pointer;
    border: 1px solid var(--border);
    overflow: hidden;
    transition: border-color 0.2s;
}

.poll-option:hover {
    border-color: var(--accent);
}

.poll-option-bar {
    position: absolute;
    top: 0;
    left: 0;
    height: 100%;
    background: var(--accent);
    opacity: 0.15;
    border-radius: 6px;
    transition: width 0.3s;
}

.poll-option-text {
    position: relative;
    z-index: 1;
    display: flex;
    justify-content: space-between;
}

.poll-option-votes {
    font-size: 12px;
    color: var(--text-muted);
}

.poll-footer {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-muted);
}

.poll-multi-badge {
    display: inline-block;
    font-size: 11px;
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
    margin-left: 4px;
}

/* Poll create modal */
.poll-modal {
    max-width: 440px;
}

.poll-options-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-bottom: 12px;
}

.poll-option-input {
    display: flex;
    gap: 6px;
    align-items: center;
}

.poll-option-input input {
    flex: 1;
    padding: 8px;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--bg-input);
    color: var(--text-primary);
    font-size: 14px;
}

.poll-option-remove {
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 16px;
    padding: 4px;
}

.poll-option-remove:hover {
    color: var(--danger);
}

/* Welcome message */
.welcome-message {
    text-align: center;
    padding: 24px 16px;
    margin: 8px 16px;
    border-bottom: 1px solid var(--border);
}

.welcome-message h3 {
    font-size: 20px;
    color: var(--text-primary);
    margin-bottom: 8px;
    font-weight: 700;
}

.welcome-message p {
    font-size: 14px;
    color: var(--text-secondary);
    max-width: 500px;
    margin: 0 auto;
}

/* Forwarded message label */
.message-forwarded {
    margin-left: 52px;
    padding: 2px 8px;
    margin-bottom: 2px;
    font-size: 12px;
    color: var(--text-muted);
    font-style: italic;
}

/* Forward dialog */
.forward-dialog {
    max-width: 400px;
}

.forward-preview {
    background: var(--bg-tertiary);
    border-radius: 6px;
    padding: 8px 12px;
    margin-bottom: 16px;
    border-left: 3px solid var(--accent);
}

.forward-preview-author {
    font-weight: 600;
    font-size: 13px;
    margin-bottom: 2px;
}

.forward-preview-content {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.forward-list {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 8px;
}

.forward-list-item {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    gap: 10px;
    transition: background-color 0.15s;
}

.forward-list-item:hover {
    background: var(--bg-tertiary);
}

.forward-item-icon {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 14px;
    overflow: hidden;
    flex-shrink: 0;
}

.forward-item-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.forward-item-name {
    font-size: 14px;
    font-weight: 500;
}

.forward-back {
    border: none;
    background: none;
    color: var(--accent);
    cursor: pointer;
    font-size: 13px;
    padding: 4px 0;
}

.forward-back:hover {
    text-decoration: underline;
}

.forward-actions {
    display: flex;
    justify-content: flex-end;
    margin-top: 12px;
}

/* Member profile card */
.profile-card {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 280px;
    overflow: hidden;
    box-shadow: 0 8px 24px var(--shadow);
}

.profile-card-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.profile-card-overlay .profile-card {
    width: calc(100vw - 32px);
    max-width: 360px;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

.profile-card-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: rgba(0, 0, 0, 0.5);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 32px;
    height: 32px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

.profile-card-close:hover {
    background: rgba(0, 0, 0, 0.7);
}

.profile-card-banner {
    height: 60px;
    overflow: hidden;
    background: var(--accent);
}

.profile-card-banner img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-card-banner-empty {
    height: 60px;
    background: linear-gradient(135deg, var(--accent), var(--bg-tertiary));
}

.profile-card-body {
    padding: 12px 16px 16px;
}

.profile-card-avatar-wrap {
    position: relative;
    display: inline-block;
    margin-top: -36px;
}

.profile-card-avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    box-shadow: 0 0 0 3px var(--bg-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 20px;
    overflow: hidden;
}

.profile-card-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-card-presence {
    position: absolute;
    bottom: 2px;
    right: 2px;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    border: 3px solid var(--bg-secondary);
    box-sizing: content-box;
}

.profile-card-name {
    font-weight: 700;
    font-size: 16px;
    margin-top: 8px;
}

.profile-card-status {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 4px;
    display: flex;
    align-items: center;
    gap: 4px;
}

.profile-card-bio {
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.profile-card-section {
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.profile-card-section-title {
    font-size: 11px;
    text-transform: uppercase;
    color: var(--text-muted);
    font-weight: 700;
    letter-spacing: 0.5px;
    margin-bottom: 6px;
}

.profile-card-servers {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.profile-card-server {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
}

.profile-card-server-icon {
    width: 24px;
    height: 24px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 11px;
    font-weight: 700;
    overflow: hidden;
    flex-shrink: 0;
}

.profile-card-server-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-card-username {
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 2px;
}

/* Profile card roles */
.profile-card-roles {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
}

.profile-card-role {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border: 1px solid;
    border-radius: 12px;
    font-size: 11px;
    font-weight: 500;
}

.profile-card-role-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

/* Role management checkboxes */
.profile-card-role-checkboxes {
    display: flex;
    flex-direction: column;
    gap: 4px;
    max-height: 120px;
    overflow-y: auto;
}

.profile-card-role-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    cursor: pointer;
    padding: 2px 0;
}

.profile-card-role-checkbox input[type="checkbox"] {
    width: 14px;
    height: 14px;
    cursor: pointer;
}

/* Kick/Ban actions in card */
.profile-card-actions {
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding-top: 8px;
    border-top: 1px solid var(--border);
}

.profile-card-actions .btn-sm {
    padding: 4px 12px;
    font-size: 12px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
}

.profile-card-actions .btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.profile-card-actions .btn-secondary:hover {
    background: var(--bg-primary);
}

.profile-card-actions .btn-danger {
    background: var(--danger);
    color: #fff;
}

.profile-card-actions .btn-danger:hover {
    opacity: 0.85;
}

/* Pinned messages panel */
.pinned-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    width: 380px;
    max-height: 420px;
    overflow: hidden;
    box-shadow: 0 8px 24px var(--shadow);
    display: flex;
    flex-direction: column;
}

.pinned-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.pinned-panel-header h3 {
    font-size: 14px;
    margin: 0;
}

.pinned-panel-close {
    border: none;
    background: none;
    color: var(--text-muted);
    font-size: 18px;
    cursor: pointer;
}

.pinned-panel-close:hover {
    color: var(--text-primary);
}

.pinned-panel-list {
    overflow-y: auto;
    padding: 8px;
    flex: 1;
}

.pinned-empty {
    text-align: center;
    color: var(--text-muted);
    padding: 16px;
    font-size: 13px;
}

.pinned-item {
    position: relative;
    padding: 8px 12px;
    border-radius: 6px;
    cursor: pointer;
    margin-bottom: 4px;
    transition: background 0.15s;
}

/* Разделитель через ::after — не доходит до скруглённых углов при hover */
.pinned-item::after {
    content: '';
    position: absolute;
    left: 12px;
    right: 12px;
    bottom: -2px;
    height: 1px;
    background: var(--border);
    pointer-events: none;
}

.pinned-item:last-child {
    margin-bottom: 0;
}

.pinned-item:last-child::after {
    display: none;
}

.pinned-item:hover {
    background: var(--bg-tertiary);
}

.pinned-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.pinned-item-author {
    font-weight: 600;
    font-size: 13px;
}

.pinned-item-time {
    font-size: 11px;
    color: var(--text-muted);
}

.pinned-item-content {
    font-size: 13px;
    color: var(--text-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pinned-item-attachments {
    display: flex;
    flex-wrap: nowrap;
    gap: 4px;
    margin-top: 4px;
    align-items: center;
}

.pinned-video-thumb {
    position: relative;
    display: inline-block;
}

.pinned-play-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 12px;
    color: #fff;
    text-shadow: 0 1px 3px rgba(0,0,0,0.6);
}

.pinned-audio-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
}

.pinned-voice-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 12px;
    color: var(--accent);
    background: var(--bg-tertiary);
    padding: 3px 8px;
    border-radius: 12px;
    font-weight: 500;
}

.pinned-file-badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    font-size: 11px;
    color: var(--text-muted);
    background: var(--bg-tertiary);
    padding: 2px 6px;
    border-radius: 4px;
}

.pinned-link-preview {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    padding: 4px 6px;
    background: var(--bg-tertiary);
    border-radius: 4px;
    border-left: 2px solid var(--accent);
}

.pinned-link-img {
    width: 32px;
    height: 32px;
    border-radius: 3px;
    object-fit: cover;
    flex-shrink: 0;
}

.pinned-link-title {
    font-size: 11px;
    color: var(--accent);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pinned-att-tile {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    border-radius: 4px;
    background: var(--bg-tertiary);
    color: var(--text-muted);
    font-size: 14px;
    vertical-align: middle;
}

.pinned-att-more {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
}

.pinned-att-spacer {
    visibility: hidden;
}

.pinned-item-unpin-tile {
    width: 56px;
    height: 56px;
    border-radius: 4px;
    border: 1px dashed var(--danger);
    background: none;
    color: var(--danger);
    font-size: 18px;
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    opacity: 0.5;
    transition: opacity 0.15s, background 0.15s;
}

.pinned-item-unpin-tile:hover {
    opacity: 1;
    background: rgba(var(--danger-rgb, 237, 66, 69), 0.15);
}

/* Animated image wrapper + GIF badge */
.message-image-wrap {
    position: relative;
    display: inline-block;
}

.gif-badge {
    position: absolute;
    bottom: 4px;
    left: 4px;
    background: rgba(0,0,0,0.7);
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    padding: 1px 4px;
    border-radius: 3px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Micro thumbnails for reply/pin previews */
.reply-micro-thumb {
    width: 56px;
    height: 56px;
    border-radius: 4px;
    object-fit: cover;
    vertical-align: middle;
    margin-right: 3px;
}

.reply-micro-thumbs {
    display: inline;
    margin-right: 4px;
}

.reply-att-icon {
    font-size: 14px;
    vertical-align: middle;
    margin-right: 2px;
}
.pinned-spoiler-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 56px;
    height: 56px;
    font-size: 8px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: var(--text-muted);
    border-radius: 4px;
    vertical-align: middle;
    margin-right: 3px;
    position: relative;
    overflow: hidden;
    background: var(--bg-tertiary);
}

.pinned-spoiler-badge img {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    filter: blur(10px);
}

.pinned-spoiler-badge span {
    position: relative;
    z-index: 1;
}

/* Private channel lock icon */
.channel-lock {
    font-size: 10px;
    margin-left: 4px;
    opacity: 0.5;
}

/* Locked channel (no access) */
.channel-item.channel-locked {
    opacity: 0.35;
    cursor: not-allowed;
}

.channel-item.channel-locked:hover {
    background: transparent;
}

/* Member without channel access */
.member-no-access {
    opacity: 0.35;
}

.member-no-access .member-name::after {
    content: ' (no access)';
    font-size: 10px;
    color: var(--text-muted);
    font-weight: 400;
}

/* Sticker suggestion popup */
.sticker-suggest {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 12px;
    margin-bottom: 4px;
    box-shadow: 0 -4px 12px var(--shadow);
    z-index: 100;
}

.sticker-suggest-label {
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 6px;
}

.sticker-suggest-list {
    display: flex;
    gap: 6px;
    overflow-x: auto;
}

.sticker-suggest-item {
    width: 56px;
    height: 56px;
    object-fit: contain;
    border-radius: 6px;
    cursor: pointer;
    border: 2px solid transparent;
    transition: border-color 0.15s, transform 0.15s;
    flex-shrink: 0;
}

.sticker-suggest-item:hover {
    border-color: var(--accent);
    transform: scale(1.1);
}

/* Inline emotes in messages */
.inline-emote {
    width: 22px;
    height: 22px;
    vertical-align: middle;
    margin: 0 1px;
    object-fit: contain;
}

/* Colon autocomplete popup */
.emote-autocomplete {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 4px;
    margin-bottom: 4px;
    box-shadow: 0 -4px 12px var(--shadow);
    z-index: 100;
    max-height: 240px;
    overflow-y: auto;
}
.emote-autocomplete-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
}
.emote-autocomplete-item:hover,
.emote-autocomplete-item.selected {
    background: var(--bg-tertiary);
}
.emote-autocomplete-img {
    width: 24px;
    height: 24px;
    object-fit: contain;
}
.emote-autocomplete-name {
    font-size: 14px;
    color: var(--text-primary);
}

/* Pack popup */
.pack-popup-overlay { position: fixed; inset: 0; z-index: 5000; }
.pack-popup {
    position: fixed;
    width: 340px;
    background: var(--bg-secondary);
    border-radius: 12px;
    box-shadow: 0 8px 24px var(--shadow);
    overflow: hidden;
}
.pack-popup-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.pack-popup-meta { font-size: 12px; color: var(--text-muted); display: block; }
.pack-popup-close { border: none; background: none; color: var(--text-muted); font-size: 18px; cursor: pointer; }
.pack-popup-close:hover { color: var(--text-primary); }
.pack-popup-desc { padding: 8px 16px; font-size: 13px; color: var(--text-secondary); margin: 0; }
.pack-popup-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 6px;
    padding: 12px 16px;
    max-height: 200px;
    overflow-y: auto;
}
.pack-popup-item {
    aspect-ratio: 1;
    cursor: pointer;
    border-radius: 6px;
    overflow: hidden;
    display: flex;
    align-items: center;
    justify-content: center;
}
.pack-popup-item img { width: 100%; height: 100%; object-fit: contain; }
.pack-popup-item:hover { background: var(--bg-tertiary); }
.pack-popup-actions {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 8px;
}

/* Clickable stickers in messages */
.message-sticker-clickable {
    cursor: pointer;
}
.message-sticker-clickable:hover img {
    filter: brightness(1.1);
}

/* Clickable avatar and author in messages (Task 1) */
.message-avatar-clickable {
    cursor: pointer;
    transition: opacity 0.15s;
}
.message-avatar-clickable:hover {
    opacity: 0.8;
}
.message-author-clickable {
    cursor: pointer;
}
.message-author-clickable:hover {
    text-decoration: underline;
}

/* Day separator (Task 2) */
.day-separator {
    display: flex;
    align-items: center;
    margin: 16px 0;
    gap: 12px;
}
.day-separator::before,
.day-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.day-separator-text {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    white-space: nowrap;
}

/* Scroll-to-bottom button (Task 3) */
.scroll-to-bottom {
    position: absolute;
    bottom: 80px;
    right: 24px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 2px 8px var(--shadow);
    z-index: 50;
    display: none;
    align-items: center;
    justify-content: center;
    display: none;
}
.scroll-to-bottom:hover {
    background: var(--bg-tertiary);
}
.scroll-to-bottom.has-unread {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
    border-radius: 20px;
    width: auto;
    height: auto;
    padding: 6px 14px;
    font-size: 13px;
    gap: 4px;
}
.scroll-to-bottom.has-unread:hover {
    background: var(--accent-hover);
}

/* New messages indicator line (Task 3) */
.new-messages-line {
    display: flex;
    align-items: center;
    margin: 8px 0;
    gap: 8px;
}
.new-messages-line::before,
.new-messages-line::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--danger);
}
.new-messages-line span {
    font-size: 11px;
    font-weight: 600;
    color: var(--danger);
    white-space: nowrap;
}

/* Mute dropdown */
.mute-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 4px;
    box-shadow: 0 4px 12px var(--shadow);
    z-index: 200;
    min-width: 180px;
}
.mute-dropdown-item {
    display: block;
    width: 100%;
    padding: 6px 10px;
    border: none;
    background: none;
    color: var(--text-primary);
    font-size: 13px;
    text-align: left;
    cursor: pointer;
    border-radius: 4px;
}
.mute-dropdown-item:hover { background: var(--bg-tertiary); }
.chat-header-btn.muted { color: var(--danger); opacity: 1; }

/* Profile card interests */
.profile-card-interests {
    margin-top: 8px;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 2px;
}

/* ===== MOBILE RESPONSIVE ===== */

/* Desktop: wrapper for servers+channels sidebar */
.mobile-left-sidebar {
    display: flex;
    flex-shrink: 0;
}

/* Mobile hamburger + members buttons (hidden on desktop) */
.mobile-nav-btn {
    display: none;
    align-items: center;
    justify-content: center;
    background: none;
    border: none;
    color: var(--text-secondary, #b9bbbe);
    font-size: 20px;
    cursor: pointer;
    padding: 4px 8px;
}

/* Mobile backdrop — hidden by default on all sizes */
.mobile-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 99;
    display: none;
}
.mobile-backdrop.visible {
    display: block;
}

/* Pinned messages bottom-sheet (mobile).
   ВНЕ media-query — класс .pinned-panel-mobile навешивается JS-ом только на
   мобилке (Mobile.isMobile()), значит стили безопасны глобально.
   z-index 9999/9998 — выше всего регулярного UI (chat-header, message-input, etc). */
.pinned-panel.pinned-panel-mobile {
    position: fixed !important;
    left: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    top: auto !important;
    width: 100% !important;
    max-width: 100% !important;
    max-height: min(70vh, calc(var(--vvh, 100vh) - 80px)) !important;
    border-radius: 16px 16px 0 0;
    transform: translateY(100%);
    transition: transform 250ms ease-out;
    z-index: 9999;
    overscroll-behavior: contain; /* скролл списка пинов не утекает в чат под ним */
}
.pinned-panel.pinned-panel-mobile.open {
    transform: translateY(0);
}
/* Drag-handle (визуальная полоска-индикатор) */
.pinned-panel-mobile::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 8px auto 4px;
    flex-shrink: 0;
}
/* Backdrop — лёгкое затемнение + click-catcher + блокиратор touch-скролла.
   touch-action: none критично: без него body.overflow:hidden не спасает от
   скролла .chat-messages (у него собственный overflow-y), и жесты прокрутки
   через backdrop доходят до чата.
   opacity: 0 → 1 с transition даёт плавный fade-in синхронно с slide-up шторки.
   pointer-events всегда auto — hit-test работает даже при opacity 0. */
.pinned-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.42);
    z-index: 9998;
    touch-action: none;
    opacity: 0;
    transition: opacity 250ms ease-out;
}
.pinned-backdrop.visible {
    opacity: 1;
}

/* Pinned item attachments — fluid 5-slot layout (desktop + mobile).
   Тайлы делят ширину строки на 5 равных слотов: calc((100% - 16px) / 5)
   = 5 элементов минус 4 gap по 4px. Unpin-кнопка всегда в 5-м слоте
   благодаря spacer'ам (.pinned-att-spacer, visibility:hidden, участвуют
   в layout). Ширина тайла адаптируется: на 380px desktop-панели ~64px,
   на мобилке — подстраивается под ширину экрана. */
.pinned-panel .pinned-item-attachments {
    gap: 4px;
}
.pinned-panel .pinned-item-attachments > .pinned-att-tile,
.pinned-panel .pinned-item-attachments > .pinned-item-unpin-tile,
.pinned-panel .pinned-item-attachments > .pinned-spoiler-badge,
.pinned-panel .pinned-item-attachments > .reply-micro-thumb,
.pinned-panel .pinned-item-attachments > .pinned-video-thumb {
    width: calc((100% - 16px) / 5);
    height: auto;
    aspect-ratio: 1 / 1;
    flex: 0 0 auto;
    margin: 0;
}
.pinned-panel .pinned-item-attachments > .reply-micro-thumb {
    object-fit: cover;
}
/* Видео-превью: контейнер fluid, картинка внутри на 100% */
.pinned-panel .pinned-item-attachments > .pinned-video-thumb {
    display: flex;
    overflow: hidden;
    border-radius: 4px;
}
.pinned-panel .pinned-item-attachments > .pinned-video-thumb > .reply-micro-thumb {
    width: 100%;
    height: 100%;
    aspect-ratio: auto;
    margin: 0;
}
/* Мобилка — чуть меньший font-size для emoji-иконок внутри тайлов,
   т.к. тайлы на узких экранах становятся меньше */
.pinned-panel-mobile .pinned-item-attachments > .pinned-att-tile {
    font-size: 12px;
}

/* Мобилка — крупный крестик закрытия, достаточная touch-зона (48×48px per Material) */
.pinned-panel-mobile .pinned-panel-close {
    font-size: 32px;
    width: 48px;
    height: 48px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    padding: 0;
    margin-right: -12px; /* Компенсируем header padding, чтоб крестик визуально в углу */
}

/* Text-only pin: текст заполняет всю зону вложений, unpin справа.
   Без фона/рамок — плоский текст, как обычный .pinned-item-content,
   но в 3 строки и занимает всю ширину. Unpin выравнен по верху. */
.pinned-item-attachments.pinned-item-text-only {
    align-items: flex-start;
}
.pinned-text-fill {
    flex: 1 1 0;
    min-width: 0;
    font-size: 13px;
    line-height: 1.4;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 3;
    overflow: hidden;
    word-break: break-word;
    white-space: pre-wrap;
}

@media (max-width: 767px), ((pointer: coarse) and (hover: none) and (max-width: 1280px)) {
    .mobile-left-sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        width: 280px;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
        background: var(--bg-secondary, #2f3136);
        overflow: hidden;
    }
    .mobile-left-sidebar.open {
        transform: translateX(0);
    }

    .mobile-left-sidebar .servers-sidebar,
    .mobile-left-sidebar .channel-sidebar {
        display: flex !important;
        flex-direction: column;
    }
    .mobile-left-sidebar .channel-sidebar {
        flex: 1;
    }

    .members-sidebar {
        position: fixed;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        height: 75vh;
        z-index: 100;
        transform: translateY(100%);
        transition: transform 0.3s ease;
        background: var(--bg-secondary, #2f3136);
        border-radius: 16px 16px 0 0;
    }
    .members-sidebar.open {
        transform: translateY(0);
    }

    .chat-layout {
        width: 100vw;
        max-width: 100vw;
    }

    .chat-area {
        width: 100vw !important;
        max-width: 100vw !important;
        flex: 1 !important;
        overflow-x: hidden;
    }

    .chat-header {
        max-width: 100vw;
        overflow: hidden;
        position: relative;
    }

    /* Mobile: hide inline search, show search button */
    .chat-search {
        display: none;
    }

    .mobile-search-btn {
        display: inline-flex !important;
    }

    /* Search overlay: full header width when active */
    .chat-header.search-open .chat-search {
        display: block;
        position: absolute;
        inset: 0;
        width: 100%;
        height: 100%;
        border: none;
        border-radius: 0;
        border-bottom: 2px solid var(--accent);
        padding: 0 16px;
        font-size: 16px;
        z-index: 5;
    }

    .chat-messages {
        max-width: 100vw;
        padding: 8px;
    }

    .message-content {
        overflow-wrap: anywhere;
    }

    .message-image {
        max-width: 100%;
    }

    .message-video-wrap {
        max-width: 100%;
    }

    .link-preview-card {
        max-width: 100%;
    }

    .chat-input-area {
        max-width: 100vw;
        padding: 8px;
    }

    .input-row {
        max-width: 100%;
        gap: 4px;
    }

    /* Mobile file previews: bigger items, 3 per row max */
    .file-preview {
        gap: 6px;
        padding: 8px;
    }

    .file-preview-item {
        min-width: calc((100vw - 40px) / 3);
        max-width: calc((100vw - 40px) / 3);
        aspect-ratio: 1;
        flex-direction: column;
        justify-content: center;
        align-items: center;
        padding: 6px;
    }

    .file-preview-thumb {
        width: 100%;
        height: 100%;
        object-fit: cover;
    }

    .file-preview-name {
        display: none;
    }

    /* Hide tiny overlay buttons on mobile — popup handles actions */
    .file-preview-remove,
    .file-preview-spoiler {
        pointer-events: none;
        opacity: 0 !important;
    }

    /* Mobile edit attachments: same treatment as pending previews */
    .edit-attachments-list {
        gap: 6px;
    }

    .edit-att-item {
        width: calc((100% - 12px) / 3);
        height: auto;
        aspect-ratio: 1;
    }

    .edit-att-remove,
    .edit-att-spoiler {
        pointer-events: none;
        opacity: 0 !important;
    }


    .mobile-nav-btn {
        display: inline-flex;
    }

    /* Hide hover menu on mobile — use long-press instead */
    .message-hover-menu {
        display: none !important;
    }

    /* Prevent text selection on long-press (messages use long-press for context menu) */
    .message {
        -webkit-user-select: none;
        user-select: none;
        -webkit-touch-callout: none;
    }
    .message .message-text,
    .message .message-text * {
        -webkit-user-select: text;
        user-select: text;
    }

    /* Hide desktop members toggle on mobile — mobile version uses slide-in */
    .desktop-only-btn {
        display: none !important;
    }

    /* Channel name opens members panel on tap */
    .chat-header-channel-name {
        cursor: pointer;
        padding: 4px 8px;
        border-radius: 4px;
        transition: background 0.15s;
    }
    .chat-header-channel-name:active {
        background: var(--bg-tertiary);
    }

    /* Override desktop members-hidden — on mobile, members is always in DOM (slide-in) */
    .chat-layout.members-hidden .members-sidebar {
        display: flex !important;
    }

    /* Emoji panel — full width on mobile */
    .emoji-panel {
        left: 0 !important;
        right: 0 !important;
        bottom: 60px !important;
        top: auto !important;
        width: 100% !important;
        max-height: 65vh;
        border-radius: 12px 12px 0 0;
    }

    /* Move tabs (Emoji/Stickers/GIF) to bottom on mobile */
    .emoji-panel-tabs {
        order: 99;
        border-bottom: none;
        border-top: 1px solid var(--border);
    }

    /* Custom video player — larger controls and progress on mobile */
    .cvp-controls {
        gap: 4px;
        padding: 8px;
        flex-wrap: wrap;
    }

    .cvp-btn {
        width: 40px;
        height: 36px;
        font-size: 16px;
    }

    .cvp-progress {
        height: 10px;
        flex-basis: 100%;
        order: -1;
        margin-bottom: 6px;
    }

    .cvp-progress:hover {
        height: 12px;
    }

    /* Hide desktop volume slider on mobile — use mute toggle instead */
    .cvp-volume {
        display: none;
    }

    .cvp-time {
        font-size: 12px;
        min-width: 36px;
    }

    .cvp-volume-btn {
        font-size: 18px;
    }

}

/* ── Drag Engine ── */
.channel-item.dragging,
.channel-category.dragging {
    opacity: 0.3;
}

.drag-placeholder {
    background: var(--accent);
    opacity: 0.25;
    border-radius: 4px;
    min-height: 28px;
    border: 2px dashed var(--accent);
}

.channel-item.drag-charging {
    animation: drag-charge 2s linear forwards;
}

@keyframes drag-charge {
    0%   { box-shadow: inset 0 0 0 0 var(--accent); }
    100% { box-shadow: inset 0 0 0 3px var(--accent); }
}

.drag-ghost {
    border-radius: 6px;
    background: var(--bg-tertiary);
}

.drag-handle {
    cursor: grab;
    color: var(--text-muted);
    padding: 0 4px;
    font-size: 14px;
    flex-shrink: 0;
    user-select: none;
}

.drag-handle:active {
    cursor: grabbing;
}

/* ── Drag: category highlight in sidebar ── */
.channel-category.drag-over .channel-category-channels {
    outline: 2px dashed var(--accent);
    outline-offset: 2px;
    border-radius: 4px;
    background: rgba(var(--accent-rgb, 88, 101, 242), 0.07);
    min-height: 24px;
}
