:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --bg: #0f172a;
    --bg-secondary: #1e293b;
    --bg-tertiary: #334155;
    --text: #f1f5f9;
    --text-muted: #94a3b8;
    --border: #334155;
    --success: #22c55e;
    --error: #ef4444;
    --mine-bg: #4f46e5;
    --their-bg: #1e293b;
    --radius: 12px;
    --safe-top: env(safe-area-inset-top, 0px);
    --safe-right: env(safe-area-inset-right, 0px);
    --safe-bottom: env(safe-area-inset-bottom, 0px);
    --safe-left: env(safe-area-inset-left, 0px);
}

@supports (-webkit-touch-callout: none) {
    @media (display-mode: standalone) {
        :root {
            --safe-top: max(env(safe-area-inset-top, 0px), 44px);
        }
    }
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    overflow: hidden;
}

/* Auth pages */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100dvh;
    padding: calc(20px + var(--safe-top)) calc(20px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
    background: linear-gradient(135deg, #0f172a 0%, #1e1b4b 100%);
}

.auth-container {
    width: 100%;
    max-width: 400px;
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 32px 24px;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
}

.auth-logo {
    text-align: center;
    margin-bottom: 28px;
}

.auth-logo h1 {
    margin-top: 12px;
    font-size: 1.5rem;
    font-weight: 700;
}

.auth-form .form-group {
    margin-bottom: 16px;
}

.auth-form label {
    display: block;
    margin-bottom: 6px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.auth-form input {
    width: 100%;
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

.auth-form input:focus {
    border-color: var(--primary);
}

.auth-link {
    text-align: center;
    margin-top: 20px;
    font-size: 0.875rem;
    color: var(--text-muted);
}

.auth-link a {
    color: var(--primary);
    text-decoration: none;
}

.auth-link a:hover {
    text-decoration: underline;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 12px 20px;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-dark);
}

.btn-block {
    width: 100%;
}

.btn-icon {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text-muted);
    cursor: pointer;
    text-decoration: none;
    transition: background 0.2s, color 0.2s;
}

.btn-icon:hover {
    background: var(--bg-tertiary);
    color: var(--text);
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 8px;
    margin-bottom: 16px;
    font-size: 0.875rem;
}

.alert-error {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

/* App layout */
.status-bar-fill {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: var(--safe-top);
    background: var(--bg-secondary);
    z-index: 999;
    pointer-events: none;
}

.safe-top-spacer {
    height: var(--safe-top);
    flex-shrink: 0;
    background: var(--bg-secondary);
}

.app {
    display: flex;
    height: 100dvh;
    max-width: 1200px;
    margin: 0 auto;
    padding-left: var(--safe-left);
    padding-right: var(--safe-right);
    box-sizing: border-box;
}

/* Sidebar */
.sidebar {
    width: 340px;
    min-width: 340px;
    display: flex;
    flex-direction: column;
    border-right: 1px solid var(--border);
    background: var(--bg-secondary);
}

.sidebar-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}

.sidebar-header h1 {
    font-size: 1.25rem;
    font-weight: 700;
}

.sidebar-actions {
    display: flex;
    align-items: center;
    gap: 4px;
}

.search-box {
    padding: 8px 12px;
}

.search-box input {
    width: 100%;
    padding: 10px 14px;
    border: none;
    border-radius: 8px;
    background: var(--bg);
    color: var(--text);
    font-size: 0.875rem;
    outline: none;
}

.connection-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 0 12px 8px;
    padding: 8px 10px;
    border: 1px solid rgba(51, 65, 85, 0.8);
    border-radius: 999px;
    background: rgba(15, 23, 42, 0.55);
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 1;
}

.connection-indicator-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--success);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.12);
    flex-shrink: 0;
}

.connection-indicator[data-state="reconnecting"] .connection-indicator-dot {
    background: #f59e0b;
    box-shadow: 0 0 0 3px rgba(245, 158, 11, 0.14);
}

.connection-indicator[data-state="offline"] .connection-indicator-dot {
    background: var(--error);
    box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.14);
}

.connection-indicator[data-state="reconnecting"] .connection-indicator-label,
.connection-indicator[data-state="offline"] .connection-indicator-label {
    color: var(--text);
}

/* Toast */
.toast-container {
    position: fixed;
    left: 50%;
    bottom: calc(24px + var(--safe-bottom));
    transform: translateX(-50%);
    z-index: 200;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.connection-toast {
    padding: 12px 18px;
    border-radius: 12px;
    background: rgba(30, 41, 59, 0.96);
    border: 1px solid rgba(34, 197, 94, 0.35);
    color: #bbf7d0;
    font-size: 0.875rem;
    font-weight: 500;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
    opacity: 0;
    transform: translateY(12px);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

.connection-toast.visible {
    opacity: 1;
    transform: translateY(0);
}

@media (max-width: 768px) {
    .toast-container {
        bottom: calc(80px + var(--safe-bottom));
        width: calc(100% - 32px);
        max-width: 360px;
    }

    .connection-toast {
        width: 100%;
        text-align: center;
    }
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(51, 65, 85, 0.5);
}

.chat-item:hover,
.chat-item.active {
    background: var(--bg-tertiary);
}

.chat-item-info {
    flex: 1;
    min-width: 0;
}

.chat-item-top {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 8px;
}

.chat-item-name {
    font-weight: 600;
    font-size: 0.9375rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    flex-shrink: 0;
}

.chat-item-bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2px;
}

.chat-item-preview {
    font-size: 0.8125rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

.unread-badge {
    background: var(--primary);
    color: white;
    font-size: 0.6875rem;
    font-weight: 700;
    min-width: 20px;
    height: 20px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 6px;
    flex-shrink: 0;
    margin-left: 8px;
}

/* Avatar */
.avatar {
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-weight: 700;
    color: white;
    flex-shrink: 0;
    position: relative;
}

.avatar-sm {
    width: 40px;
    height: 40px;
    font-size: 0.8125rem;
}

.avatar-md {
    width: 48px;
    height: 48px;
    font-size: 0.9375rem;
}

.online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 12px;
    height: 12px;
    background: var(--success);
    border: 2px solid var(--bg-secondary);
    border-radius: 50%;
}

/* Chat area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg);
    min-width: 0;
}

.chat-placeholder {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    color: var(--text-muted);
}

.chat-window {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

.chat-window.hidden {
    display: none;
}

.chat-header {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
}

.chat-header-info {
    flex: 1;
}

.chat-header-name {
    font-weight: 600;
    font-size: 1rem;
}

.chat-header-status {
    font-size: 0.75rem;
    color: var(--text-muted);
}

.chat-header-status.online {
    color: var(--success);
}

/* Messages */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    -webkit-overflow-scrolling: touch;
}

.messages-virtual-host {
    display: block;
}

.virtual-viewport {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.virtual-spacer-top,
.virtual-spacer-bottom {
    width: 100%;
    flex-shrink: 0;
}

.message.pending {
    opacity: 0.72;
}

.message.failed {
    outline: 1px solid rgba(239, 68, 68, 0.45);
}

.message-retry-btn {
    margin-left: 6px;
    border: none;
    background: rgba(239, 68, 68, 0.2);
    color: #fca5a5;
    border-radius: 6px;
    padding: 2px 8px;
    font-size: 0.6875rem;
    cursor: pointer;
}

.message-status.pending {
    font-size: 0.75rem;
    opacity: 0.7;
}

.message-status.failed {
    color: #ef4444;
    font-weight: 700;
}

.message {
    max-width: 75%;
    padding: 8px 12px;
    border-radius: 16px;
    font-size: 0.9375rem;
    line-height: 1.4;
    word-wrap: break-word;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(4px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.mine {
    align-self: flex-end;
    background: var(--mine-bg);
    border-bottom-right-radius: 4px;
}

.message.theirs {
    align-self: flex-start;
    background: var(--their-bg);
    border-bottom-left-radius: 4px;
}

.message-time {
    font-size: 0.6875rem;
    color: rgba(255, 255, 255, 0.5);
    margin-top: 4px;
    text-align: right;
}

.message.theirs .message-time {
    color: var(--text-muted);
}

/* Message form */
.message-form {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 12px 16px;
    padding-bottom: calc(12px + var(--safe-bottom));
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.message-form input {
    flex: 1;
    padding: 12px 16px;
    border: none;
    border-radius: 24px;
    background: var(--bg);
    color: var(--text);
    font-size: 1rem;
    outline: none;
}

.btn-send {
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: var(--primary);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.2s, transform 0.1s;
}

.btn-send:hover {
    background: var(--primary-dark);
}

.btn-send:active {
    transform: scale(0.95);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.hidden {
    display: none !important;
}

.announcement-banner {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    background: linear-gradient(135deg, #4338ca, #6366f1);
    color: #fff;
    padding: calc(12px + var(--safe-top)) calc(16px + var(--safe-right)) 12px calc(16px + var(--safe-left));
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
}

.announcement-banner-inner {
    max-width: 960px;
    margin: 0 auto;
    display: flex;
    align-items: flex-start;
    gap: 16px;
    justify-content: space-between;
}

.announcement-banner-text strong {
    display: block;
    font-size: 0.9375rem;
    margin-bottom: 4px;
}

.announcement-banner-text p {
    margin: 0;
    font-size: 0.875rem;
    opacity: 0.95;
    white-space: pre-wrap;
}

.announcement-banner:not(.hidden) ~ .status-bar-fill {
    display: none;
}

.announcement-banner:not(.hidden) ~ .app {
    padding-top: 0;
}

.announcement-banner:not(.hidden) ~ .app {
    padding-top: 72px;
}

.announcement-banner:not(.hidden) ~ .app .safe-top-spacer {
    display: none;
}

@media (max-width: 640px) {
    .announcement-banner-inner {
        flex-direction: column;
        align-items: stretch;
    }
}

body.lightbox-open {
    overflow: hidden;
}

.loading, .empty-state {
    padding: 32px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
}

/* Mobile */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        min-width: 100%;
    }

    .chat-area {
        display: none;
        position: fixed;
        inset: 0;
        z-index: 10;
    }

    .app.chat-open .status-bar-fill {
        background: var(--bg-secondary);
    }

    .app.chat-open .sidebar {
        display: none;
    }

    .app.chat-open .chat-area {
        display: flex;
    }

    .back-btn {
        display: flex;
    }
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--bg-tertiary);
    border-radius: 3px;
}

.back-btn {
    display: none;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-group {
    display: flex;
    align-items: center;
    justify-content: center;
}

.group-badge {
    font-size: 0.6875rem;
    color: var(--text-muted);
    font-weight: 400;
}

.message-sender {
    font-size: 0.75rem;
    font-weight: 600;
    color: #a5b4fc;
    margin-bottom: 4px;
}

.message-image {
    display: block;
    border: none;
    padding: 0;
    margin: 0 0 4px;
    background: transparent;
    cursor: pointer;
    border-radius: 8px;
    overflow: hidden;
    max-width: min(220px, 70vw);
}

.message-image img {
    display: block;
    width: 100%;
    max-height: 220px;
    object-fit: cover;
    border-radius: 8px;
}

.image-lightbox {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(16px + var(--safe-top)) calc(16px + var(--safe-right)) calc(16px + var(--safe-bottom)) calc(16px + var(--safe-left));
    background: rgba(0, 0, 0, 0.92);
}

.image-lightbox img {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    border-radius: 4px;
}

.image-lightbox-close {
    position: absolute;
    top: calc(12px + var(--safe-top));
    right: calc(12px + var(--safe-right));
    width: 44px;
    height: 44px;
    border: none;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    font-size: 1.75rem;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-lightbox-close:hover {
    background: rgba(255, 255, 255, 0.25);
}

.message-file {
    display: flex;
    align-items: center;
    gap: 6px;
    color: inherit;
    text-decoration: none;
    padding: 8px 12px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    margin-bottom: 4px;
}

.message-file:hover {
    text-decoration: underline;
}

.file-size {
    font-size: 0.75rem;
    opacity: 0.7;
}

.attach-btn {
    flex-shrink: 0;
}

.file-preview {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 16px;
    background: var(--bg-tertiary);
    font-size: 0.875rem;
    border-top: 1px solid var(--border);
}

/* Modals */
.modal {
    position: fixed;
    inset: 0;
    z-index: 100;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: calc(20px + var(--safe-top)) calc(20px + var(--safe-right)) calc(20px + var(--safe-bottom)) calc(20px + var(--safe-left));
}

.modal-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.6);
}

.modal-content {
    position: relative;
    background: var(--bg-secondary);
    border-radius: 16px;
    padding: 24px;
    width: 100%;
    max-width: 420px;
    max-height: 80dvh;
    overflow-y: auto;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.5);
}

.modal-content h2 {
    font-size: 1.25rem;
    margin-bottom: 20px;
}

.modal-actions {
    display: flex;
    gap: 8px;
    justify-content: flex-end;
    margin-top: 20px;
}

.member-select {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px;
}

.member-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px;
    cursor: pointer;
    border-radius: 6px;
}

.member-option:hover {
    background: var(--bg-tertiary);
}

.member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 0;
    border-bottom: 1px solid var(--border);
}

.member-row:last-child {
    border-bottom: none;
}

.btn-secondary {
    background: var(--bg-tertiary);
    color: var(--text);
}

/* Avatar photo */
.avatar-photo {
    overflow: hidden;
    padding: 0 !important;
}

.avatar-photo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.avatar-wrap {
    position: relative;
    flex-shrink: 0;
}

.avatar-wrap .online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
}

.avatar-xs {
    width: 24px;
    height: 24px;
    font-size: 0.625rem;
}

.avatar-lg {
    width: 80px;
    height: 80px;
    font-size: 1.5rem;
}

.avatar-btn {
    cursor: pointer;
    border: none;
    padding: 0;
}

.btn-link {
    background: none;
    border: none;
    color: var(--primary);
    cursor: pointer;
    font-size: 0.8125rem;
    margin-top: 8px;
}

.btn-link:hover {
    text-decoration: underline;
}

.profile-avatar-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 20px;
}

.profile-avatar-wrap {
    position: relative;
}

.avatar-upload-btn {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 28px;
    height: 28px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: white;
    border: 2px solid var(--bg-secondary);
}

/* Message edit/delete */
.message {
    position: relative;
}

.message.deleted {
    opacity: 0.7;
}

.message-deleted {
    font-style: italic;
    color: var(--text-muted);
}

.message-meta {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 3px;
}

.message-status {
    position: relative;
    display: inline-block;
    width: 15px;
    height: 10px;
    color: rgba(255, 255, 255, 0.58);
    user-select: none;
    flex-shrink: 0;
    transform: translateY(0.5px);
}

.message-check {
    position: absolute;
    top: 0;
    font-size: 0.68rem;
    line-height: 1;
    font-weight: 700;
}

.message-check.first {
    left: 0;
}

.message-check.second {
    left: 5px;
    display: none;
}

.message-status.single .message-check.first {
    left: 3px;
}

.message-status.double .message-check.second {
    display: block;
}

.message-status.read {
    color: #7dd3fc;
}

.message-time {
    margin-top: 0;
    color: rgba(255, 255, 255, 0.44);
}

.message.theirs .message-time {
    color: rgba(148, 163, 184, 0.72);
}

.message.mine:not(.message-block-end) .message-status {
    display: none;
}

.message.mine:not(.message-block-end) .message-meta {
    gap: 0;
}

.message.editing {
    min-width: min(100%, 280px);
}

.message-edit {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message-edit-input {
    width: 100%;
    min-height: 36px;
    max-height: 160px;
    padding: 8px 10px;
    border: 1px solid rgba(255, 255, 255, 0.18);
    border-radius: 10px;
    background: rgba(0, 0, 0, 0.18);
    color: inherit;
    font: inherit;
    line-height: 1.4;
    resize: none;
    outline: none;
}

.message.theirs .message-edit-input {
    border-color: rgba(148, 163, 184, 0.28);
    background: rgba(255, 255, 255, 0.04);
}

.message-edit-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

.message-edit-cancel,
.message-edit-save {
    border: none;
    border-radius: 8px;
    padding: 6px 12px;
    font-size: 0.8125rem;
    cursor: pointer;
}

.message-edit-cancel {
    background: rgba(255, 255, 255, 0.08);
    color: inherit;
}

.message-edit-save {
    background: var(--primary);
    color: #fff;
}

.message-edit-cancel:disabled,
.message-edit-save:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.context-menu {
    position: fixed;
    z-index: 300;
    min-width: 160px;
    padding: 6px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--bg-secondary);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
}

.context-menu-item {
    display: block;
    width: 100%;
    padding: 10px 12px;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--text);
    font-size: 0.875rem;
    text-align: left;
    cursor: pointer;
}

.context-menu-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.context-menu-item-danger {
    color: #fca5a5;
}

.typing-indicator {
    padding: 6px 16px 0;
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-style: italic;
    min-height: 22px;
}

.message-actions {
    display: none;
    gap: 2px;
}

.message:hover .message-actions {
    display: inline-flex;
}

.msg-action {
    background: rgba(0, 0, 0, 0.2);
    border: none;
    color: inherit;
    width: 22px;
    height: 22px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1;
    opacity: 0.7;
}

.msg-action:hover {
    opacity: 1;
    background: rgba(0, 0, 0, 0.35);
}

.message.theirs .msg-action {
    background: rgba(255, 255, 255, 0.1);
}

.message-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 4px;
}

.preview-muted {
    font-style: italic;
    color: var(--text-muted);
}

@media (max-width: 768px) {
    .message-actions {
        display: inline-flex;
    }
}

/* Extended features */
.message-reply {
    border-left: 3px solid var(--primary);
    padding: 4px 8px;
    margin-bottom: 6px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.12);
    cursor: pointer;
    font-size: 0.8125rem;
}

.message-reply-author {
    display: block;
    color: var(--primary);
    font-weight: 600;
}

.message-reply-text {
    color: var(--text-muted);
    display: block;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
}

.message-forward {
    font-size: 0.75rem;
    color: var(--primary);
    margin-bottom: 4px;
    font-style: italic;
}

.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 4px;
    margin-top: 6px;
}

.reaction-chip {
    border: 1px solid rgba(255, 255, 255, 0.12);
    background: rgba(15, 23, 42, 0.5);
    border-radius: 999px;
    padding: 2px 8px;
    font-size: 0.8125rem;
    cursor: pointer;
    color: inherit;
}

.reaction-chip.mine {
    border-color: rgba(99, 102, 241, 0.6);
    background: rgba(99, 102, 241, 0.18);
}

.reaction-chip span {
    margin-left: 4px;
    font-size: 0.75rem;
    opacity: 0.8;
}

.message-highlight {
    animation: msgHighlight 1.5s ease;
}

@keyframes msgHighlight {
    0%, 100% { box-shadow: none; }
    30% { box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.45); }
}

.message-video video,
.message-voice audio {
    max-width: 100%;
    border-radius: 8px;
}

.message-pdf iframe {
    width: 100%;
    height: 200px;
    border: none;
    border-radius: 8px;
    background: #fff;
}

.message-pdf .message-file-link {
    display: block;
    margin-top: 4px;
    font-size: 0.8125rem;
}

.message-pin-badge {
    font-size: 0.6875rem;
    color: #fbbf24;
    margin-bottom: 4px;
}

.reply-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-top: 1px solid var(--border);
    background: var(--bg-secondary);
}

.reply-bar-content {
    flex: 1;
    min-width: 0;
}

.reply-bar-label {
    display: block;
    font-size: 0.75rem;
    color: var(--primary);
    font-weight: 600;
}

.reply-bar-text {
    display: block;
    font-size: 0.8125rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--text-muted);
}

.upload-progress {
    height: 3px;
    background: rgba(255, 255, 255, 0.08);
}

.upload-progress-fill {
    height: 100%;
    width: 0;
    background: var(--primary);
    transition: width 0.15s linear;
}

.pinned-bar {
    padding: 8px 16px;
    border-bottom: 1px solid var(--border);
    background: rgba(99, 102, 241, 0.08);
}

.pinned-bar-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    text-align: left;
}

.pinned-bar-text {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    font-size: 0.8125rem;
}

.message-search-panel {
    padding: 8px 12px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.message-search-panel input {
    grid-column: 1 / -1;
    padding: 8px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg);
    color: var(--text);
}

.message-search-results {
    grid-column: 1 / -1;
    max-height: 200px;
    overflow-y: auto;
}

.search-result-item {
    display: block;
    width: 100%;
    text-align: left;
    padding: 8px;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    border-radius: 6px;
}

.search-result-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.search-result-time {
    display: block;
    font-size: 0.6875rem;
    color: var(--text-muted);
}

.reaction-picker {
    position: fixed;
    z-index: 400;
    display: flex;
    gap: 4px;
    padding: 8px;
    border-radius: 999px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
}

.reaction-pick {
    border: none;
    background: transparent;
    font-size: 1.25rem;
    cursor: pointer;
    padding: 4px;
    border-radius: 8px;
}

.reaction-pick:hover {
    background: rgba(255, 255, 255, 0.08);
}

.forward-chat-list {
    max-height: 320px;
    overflow-y: auto;
}

.forward-chat-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    padding: 10px;
    border: none;
    background: transparent;
    color: var(--text);
    cursor: pointer;
    border-radius: 8px;
    text-align: left;
}

.forward-chat-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.form-check label {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.875rem;
}

.btn-danger {
    background: #dc2626;
    color: #fff;
    border: none;
    border-radius: 8px;
    padding: 8px 14px;
    cursor: pointer;
}

#voice-btn.recording {
    color: #ef4444;
    animation: pulseRec 1s infinite;
}

@keyframes pulseRec {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

.pull-refresh-indicator {
    text-align: center;
    font-size: 0.8125rem;
    color: var(--text-muted);
    padding: 4px;
    transform: translateY(-40px);
    transition: transform 0.2s ease;
    pointer-events: none;
}

.pull-refresh-indicator.visible {
    opacity: 1;
}
