/* ════════════════════════════════════════════════
   Chat Rooms — Styles
   ════════════════════════════════════════════════ */

/* ── Container ── */
.cr-container {
    max-width: 800px;
    margin: 0 auto;
    padding: 2rem 1rem;
}

.cr-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
    flex-wrap: wrap;
}

.cr-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-primary, #f1f5f9);
    flex: 1;
    margin: 0;
}

.cr-header-actions {
    display: flex;
    gap: 0.5rem;
}

.cr-back-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 8px;
    padding: 0.5rem;
    color: var(--text-primary, #f1f5f9);
    cursor: pointer;
    transition: background 0.2s;
}
.cr-back-btn:hover {
    background: rgba(255,255,255,0.1);
}

/* ── Buttons ── */
.cr-btn {
    padding: 0.5rem 1rem;
    border-radius: 8px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    border: none;
    transition: all 0.2s;
    white-space: nowrap;
}

.cr-btn-primary {
    background: var(--accent, #8b5cf6);
    color: #fff;
}
.cr-btn-primary:hover {
    background: var(--accent-dark, #6d28d9);
    transform: translateY(-1px);
}

.cr-btn-outline {
    background: transparent;
    border: 1px solid rgba(255,255,255,0.15);
    color: var(--text-primary, #f1f5f9);
}
.cr-btn-outline:hover {
    background: rgba(255,255,255,0.05);
    border-color: var(--accent, #8b5cf6);
}

.cr-btn-danger-sm {
    background: rgba(239,68,68,0.15);
    color: #f87171;
    padding: 0.35rem 0.75rem;
    font-size: 0.8rem;
    border-radius: 6px;
    border: none;
    cursor: pointer;
}
.cr-btn-danger-sm:hover {
    background: rgba(239,68,68,0.3);
}

/* ── Room List ── */
.cr-room-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.cr-empty {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--text-secondary, #94a3b8);
}

.cr-room-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.25rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}
.cr-room-card:hover {
    background: rgba(255,255,255,0.06);
    border-color: var(--accent, #8b5cf6);
    transform: translateY(-1px);
}

.cr-room-icon {
    font-size: 2rem;
    flex-shrink: 0;
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(139,92,246,0.1);
    border-radius: 12px;
}

.cr-room-info {
    flex: 1;
    min-width: 0;
}

.cr-room-name {
    font-weight: 600;
    color: var(--text-primary, #f1f5f9);
    font-size: 1rem;
    margin-bottom: 0.2rem;
}

.cr-room-meta {
    font-size: 0.8rem;
    color: var(--text-secondary, #94a3b8);
    display: flex;
    gap: 0.75rem;
    align-items: center;
}

.cr-room-preview {
    font-size: 0.8rem;
    color: var(--text-secondary, #94a3b8);
    margin-top: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 400px;
}

/* ── Chat Detail ── */
.cr-chat-container {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 80px);
    max-width: 900px;
    margin: 0 auto;
}

.cr-chat-header {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.25rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
}

.cr-chat-room-info {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.cr-chat-room-icon {
    font-size: 1.5rem;
}

.cr-chat-room-name {
    font-weight: 600;
    color: var(--text-primary, #f1f5f9);
    font-size: 1.1rem;
}

.cr-chat-room-members {
    font-size: 0.75rem;
    color: var(--text-secondary, #94a3b8);
    background: rgba(255,255,255,0.05);
    padding: 0.2rem 0.5rem;
    border-radius: 10px;
}

.cr-chat-header-actions {
    display: flex;
    gap: 0.5rem;
}

/* ── Messages Area ── */
.cr-messages-area {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.cr-messages-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    margin-top: auto;
}

.cr-msg {
    display: flex;
    gap: 0.5rem;
    max-width: 80%;
    position: relative;
    align-items: flex-end;
}

.cr-msg-own {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.cr-msg-other {
    align-self: flex-start;
}

.cr-msg-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.8rem;
    font-weight: 600;
    color: #fff;
}

.cr-msg-avatar img {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    object-fit: cover;
}

.cr-msg-bubble {
    padding: 0.6rem 1rem;
    border-radius: 16px;
    position: relative;
    word-break: break-word;
}

.cr-msg-own .cr-msg-bubble {
    background: var(--accent, #8b5cf6);
    color: #fff;
    border-bottom-right-radius: 4px;
}

.cr-msg-other .cr-msg-bubble {
    background: rgba(255,255,255,0.06);
    border: 1px solid rgba(255,255,255,0.08);
    color: var(--text-primary, #f1f5f9);
    border-bottom-left-radius: 4px;
}

.cr-msg-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--accent-light, #a78bfa);
    margin-bottom: 0.2rem;
}

.cr-msg-own .cr-msg-name {
    display: none;
}

.cr-msg-content {
    font-size: 0.9rem;
    line-height: 1.4;
}

.cr-msg-time {
    font-size: 0.65rem;
    opacity: 0.6;
    margin-top: 0.2rem;
    text-align: right;
}

.cr-msg-own .cr-msg-time {
    color: rgba(255,255,255,0.7);
}

.cr-msg-delete {
    display: none;
}

/* ── 3-dot message menu (Messenger style) ── */
.cr-msg-row {
    display: flex;
    align-items: center;
    gap: 4px;
}

.cr-msg-own .cr-msg-row {
    flex-direction: row;
}

.cr-msg-other .cr-msg-row {
    flex-direction: row;
}

.cr-msg-menu-wrap {
    position: relative;
    display: flex;
    align-items: center;
    opacity: 0;
    transition: opacity 0.15s;
}

.cr-msg:hover .cr-msg-menu-wrap {
    opacity: 1;
}

.cr-msg-menu-btn {
    background: none;
    border: none;
    color: var(--text-secondary, #94a3b8);
    font-size: 18px;
    cursor: pointer;
    padding: 4px 6px;
    border-radius: 50%;
    line-height: 1;
    transition: background 0.15s;
}

.cr-msg-menu-btn:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-primary, #f1f5f9);
}

.cr-msg-menu {
    position: fixed;
    background: #1e1e3a;
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 9999;
    padding: 4px;
    min-width: 140px;
}

.cr-msg-menu.hidden {
    display: none;
}

.cr-msg-menu-item {
    display: flex;
    align-items: center;
    gap: 8px;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    color: #f87171;
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
    text-align: left;
}

.cr-msg-menu-item:hover {
    background: rgba(248, 113, 113, 0.1);
}

/* Light mode */
.light-mode .cr-msg-menu-btn {
    color: #94a3b8;
}
.light-mode .cr-msg-menu-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: #1e293b;
}
.light-mode .cr-msg-menu {
    background: #fff;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* ── Input Bar ── */
.cr-input-bar {
    display: flex;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-top: 1px solid rgba(255,255,255,0.08);
    flex-shrink: 0;
    position: relative;
}

.cr-message-input {
    flex: 1;
    padding: 0.6rem 1rem;
    border-radius: 24px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
    color: var(--text-primary, #f1f5f9);
    font-size: 0.9rem;
    outline: none;
    transition: border-color 0.2s;
}
.cr-message-input:focus {
    border-color: var(--accent, #8b5cf6);
}
.cr-message-input::placeholder {
    color: var(--text-secondary, #94a3b8);
}

.cr-send-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: var(--accent, #8b5cf6);
    color: #fff;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, transform 0.2s;
    flex-shrink: 0;
}
.cr-send-btn:hover {
    background: var(--accent-dark, #6d28d9);
    transform: scale(1.05);
}

/* ── Modal ── */
.cr-modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
    padding: 1rem;
}
.cr-modal-overlay.hidden {
    display: none;
}

.cr-modal {
    background: var(--card-bg, #1e1b2e);
    border: 1px solid rgba(255,255,255,0.1);
    border-radius: 16px;
    width: 100%;
    max-width: 480px;
    max-height: 85vh;
    overflow: visible;
    box-shadow: 0 20px 60px rgba(0,0,0,0.5);
}

.cr-modal-lg {
    max-width: 600px;
}

.cr-modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
    border-bottom: 1px solid rgba(255,255,255,0.08);
}
.cr-modal-header h3 {
    margin: 0;
    font-size: 1.1rem;
    color: var(--text-primary, #f1f5f9);
}

.cr-modal-close {
    background: none;
    border: none;
    color: var(--text-secondary, #94a3b8);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.25rem;
    line-height: 1;
}
.cr-modal-close:hover {
    color: var(--text-primary, #f1f5f9);
}

.cr-modal-body {
    padding: 1.5rem;
}

.cr-modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding: 1rem 1.5rem;
    border-top: 1px solid rgba(255,255,255,0.08);
}

/* ── Form Elements ── */
.cr-label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary, #94a3b8);
    margin-bottom: 0.4rem;
    margin-top: 1rem;
}
.cr-label:first-child {
    margin-top: 0;
}

.cr-input {
    width: 100%;
    padding: 0.65rem 0.9rem;
    border-radius: 8px;
    border: 1px solid rgba(255,255,255,0.12);
    background: rgba(255,255,255,0.04);
    color: var(--text-primary, #f1f5f9);
    font-size: 0.9rem;
    outline: none;
    box-sizing: border-box;
}
.cr-input:focus {
    border-color: var(--accent, #8b5cf6);
}

.cr-hint {
    font-size: 0.75rem;
    color: var(--text-secondary, #94a3b8);
    margin-top: 0.3rem;
    opacity: 0.7;
}

/* ── Icon Picker ── */
.cr-icon-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
}

.cr-icon-opt {
    width: 38px;
    height: 38px;
    border-radius: 8px;
    border: 2px solid transparent;
    background: rgba(255,255,255,0.04);
    font-size: 1.2rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}
.cr-icon-opt:hover {
    background: rgba(255,255,255,0.08);
}
.cr-icon-opt.selected {
    border-color: var(--accent, #8b5cf6);
    background: rgba(139,92,246,0.15);
}

/* ── Toggle ── */
.cr-toggle-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 0;
}
.cr-toggle-row span {
    color: var(--text-primary, #f1f5f9);
    font-size: 0.9rem;
}

.cr-toggle {
    position: relative;
    width: 44px;
    height: 24px;
    display: inline-block;
}
.cr-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}
.cr-toggle-slider {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.15);
    border-radius: 24px;
    cursor: pointer;
    transition: background 0.3s;
}
.cr-toggle-slider::before {
    content: '';
    position: absolute;
    width: 18px;
    height: 18px;
    left: 3px;
    top: 3px;
    background: #fff;
    border-radius: 50%;
    transition: transform 0.3s;
}
.cr-toggle input:checked + .cr-toggle-slider {
    background: var(--accent, #8b5cf6);
}
.cr-toggle input:checked + .cr-toggle-slider::before {
    transform: translateX(20px);
}

/* ── Public Room List ── */
.cr-public-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    max-height: 400px;
    overflow-y: auto;
}

.cr-public-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.85rem 1rem;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 10px;
}

.cr-public-card-info {
    flex: 1;
    min-width: 0;
}

.cr-public-card-name {
    font-weight: 600;
    color: var(--text-primary, #f1f5f9);
    font-size: 0.95rem;
}

.cr-public-card-meta {
    font-size: 0.75rem;
    color: var(--text-secondary, #94a3b8);
    margin-top: 0.15rem;
}

/* ── Light Mode ── */
.light-mode .cr-back-btn {
    background: rgba(0,0,0,0.04);
    border-color: rgba(0,0,0,0.1);
    color: #1e293b;
}
.light-mode .cr-back-btn:hover {
    background: rgba(0,0,0,0.08);
}

.light-mode .cr-title,
.light-mode .cr-room-name,
.light-mode .cr-chat-room-name {
    color: #1e293b;
}

.light-mode .cr-room-card {
    background: rgba(0,0,0,0.02);
    border-color: rgba(0,0,0,0.08);
}
.light-mode .cr-room-card:hover {
    background: rgba(0,0,0,0.04);
    border-color: var(--accent, #8b5cf6);
}

.light-mode .cr-msg-other .cr-msg-bubble {
    background: rgba(0,0,0,0.04);
    border-color: rgba(0,0,0,0.08);
    color: #1e293b;
}

.light-mode .cr-message-input {
    background: rgba(0,0,0,0.03);
    border-color: rgba(0,0,0,0.12);
    color: #1e293b;
}

.light-mode .cr-modal {
    background: #fff;
    border-color: rgba(0,0,0,0.1);
}
.light-mode .cr-modal-header {
    border-color: rgba(0,0,0,0.08);
}
.light-mode .cr-modal-header h3 {
    color: #1e293b;
}
.light-mode .cr-modal-footer {
    border-color: rgba(0,0,0,0.08);
}

.light-mode .cr-input {
    background: rgba(0,0,0,0.03);
    border-color: rgba(0,0,0,0.12);
    color: #1e293b;
}

.light-mode .cr-icon-opt {
    background: rgba(0,0,0,0.03);
}
.light-mode .cr-icon-opt:hover {
    background: rgba(0,0,0,0.06);
}

.light-mode .cr-toggle-slider {
    background: rgba(0,0,0,0.15);
}

.light-mode .cr-toggle-row span,
.light-mode .cr-public-card-name {
    color: #1e293b;
}

.light-mode .cr-btn-outline {
    border-color: rgba(0,0,0,0.15);
    color: #1e293b;
}
.light-mode .cr-btn-outline:hover {
    background: rgba(0,0,0,0.04);
}

.light-mode .cr-chat-header {
    border-color: rgba(0,0,0,0.08);
}
.light-mode .cr-input-bar {
    border-color: rgba(0,0,0,0.08);
}

.light-mode .cr-public-card {
    background: rgba(0,0,0,0.02);
    border-color: rgba(0,0,0,0.08);
}

.light-mode .cr-room-icon {
    background: rgba(139,92,246,0.08);
}

.light-mode .cr-chat-room-members {
    background: rgba(0,0,0,0.04);
    color: #64748b;
}

/* ── Responsive ── */
@media (max-width: 640px) {
    .cr-container {
        padding: 1rem 0.75rem;
    }
    .cr-header {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
    }
    .cr-header-actions {
        width: 100%;
    }
    .cr-header-actions .cr-btn {
        flex: 1;
        text-align: center;
    }
    .cr-msg {
        max-width: 90%;
    }
    .cr-chat-container {
        height: calc(100vh - 60px);
    }
    .cr-room-preview {
        max-width: 200px;
    }
    .cr-chat-header-actions {
        flex-direction: column;
        gap: 0.25rem;
    }
}
/* Hide global footer when chat rooms are visible */

/* ── Image upload button ── */
.cr-img-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary, #94a3b8);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s;
}

.cr-img-btn:hover {
    background: rgba(139, 92, 246, 0.15);
    border-color: rgba(139, 92, 246, 0.3);
    color: #a78bfa;
}

/* ── Image preview (before send) ── */
.cr-img-preview {
    padding: 8px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
    position: relative;
    display: flex;
    align-items: center;
}

.cr-img-preview img {
    max-height: 120px;
    max-width: 200px;
    border-radius: 10px;
    object-fit: cover;
}

.cr-img-preview-close {
    position: absolute;
    top: 4px;
    right: 12px;
    background: rgba(239, 68, 68, 0.9);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Image in message bubble ── */
.cr-msg-image {
    margin: 4px 0;
}

.cr-msg-image img {
    max-width: 250px;
    max-height: 200px;
    border-radius: 10px;
    cursor: pointer;
    transition: opacity 0.2s;
    display: block;
}

.cr-msg-image img:hover {
    opacity: 0.85;
}

/* ── Full-screen image viewer ── */
.cr-img-viewer {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 99999;
    cursor: pointer;
}

.cr-img-viewer img {
    max-width: 90vw;
    max-height: 90vh;
    border-radius: 8px;
    object-fit: contain;
}

.cr-img-viewer-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 40px;
    height: 40px;
    font-size: 20px;
    cursor: pointer;
}

/* Light mode */
.light-mode .cr-img-btn {
    background: rgba(0, 0, 0, 0.04);
    border-color: rgba(0, 0, 0, 0.1);
    color: #64748b;
}
.light-mode .cr-img-btn:hover {
    background: rgba(139, 92, 246, 0.08);
    color: #7c3aed;
}
.light-mode .cr-img-preview {
    border-color: rgba(0, 0, 0, 0.08);
}

/* ── Pinned badge ── */
.cr-msg-pinned {
    font-size: 0.65rem;
    color: #fbbf24;
    margin-bottom: 2px;
    font-weight: 600;
}

/* ── Menu danger item ── */
.cr-msg-menu-item.cr-msg-menu-danger {
    color: #f87171;
}
.cr-msg-menu-item.cr-msg-menu-danger:hover {
    background: rgba(248, 113, 113, 0.1);
}

/* ── Members panel ── */
.cr-members-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.cr-member-row {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
}

.cr-member-row:hover {
    background: rgba(255, 255, 255, 0.06);
}

.cr-member-av {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: 700;
    color: #fff;
    flex-shrink: 0;
    object-fit: cover;
}

img.cr-member-av {
    object-fit: cover;
}

.cr-member-name {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary, #f1f5f9);
}

.cr-creator-badge {
    font-size: 12px;
}

.cr-member-actions {
    display: flex;
    gap: 4px;
}

.light-mode .cr-member-row {
    background: rgba(0, 0, 0, 0.02);
}
.light-mode .cr-member-row:hover {
    background: rgba(0, 0, 0, 0.04);
}

/* ── Admin badge ── */
.cr-admin-badge {
    font-size: 11px;
    color: #60a5fa;
    font-weight: 600;
}

.cr-creator-badge {
    font-size: 11px;
    color: #fbbf24;
    font-weight: 600;
}

/* ── Report items ── */
.cr-report-item {
    padding: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 10px;
    margin-bottom: 10px;
}

.cr-report-header {
    font-size: 13px;
    color: var(--text-secondary, #94a3b8);
    margin-bottom: 6px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 4px;
}

.cr-report-header strong {
    color: var(--text-primary, #f1f5f9);
}

.cr-report-time {
    font-size: 11px;
    opacity: 0.6;
}

.cr-report-content {
    font-size: 14px;
    color: var(--text-primary, #f1f5f9);
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 8px;
    margin: 6px 0;
    font-style: italic;
}

.cr-report-reason {
    font-size: 12px;
    color: #fbbf24;
    margin-bottom: 8px;
}

.cr-report-actions {
    display: flex;
    gap: 6px;
}

/* ── Reports badge on header button ── */
.cr-reports-btn {
    position: relative;
}

.cr-reports-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0 3px;
    animation: crReportPulse 2s infinite;
}

@keyframes crReportPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.15); }
}

/* ── Mute badge ── */
.cr-mute-badge {
    font-size: 11px;
    color: #f87171;
    background: rgba(248, 113, 113, 0.1);
    padding: 2px 6px;
    border-radius: 4px;
    font-weight: 600;
    margin-left: 6px;
}

/* ── Mute bar (replaces input when muted) ── */
.cr-mute-bar {
    padding: 14px 20px;
    text-align: center;
    background: rgba(248, 113, 113, 0.08);
    border-top: 1px solid rgba(248, 113, 113, 0.2);
    color: #f87171;
    font-size: 14px;
    flex-shrink: 0;
}

.cr-mute-bar strong {
    color: #fca5a5;
}

/* ── Pinned messages trigger ── */
.cr-pinned-trigger {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 16px;
    border-bottom: 1px solid rgba(251, 191, 36, 0.15);
    background: rgba(251, 191, 36, 0.04);
    cursor: pointer;
    flex-shrink: 0;
    font-size: 13px;
    color: #fbbf24;
    transition: background 0.15s;
}

.cr-pinned-trigger:hover {
    background: rgba(251, 191, 36, 0.08);
}

.cr-pinned-arrow {
    margin-left: auto;
    opacity: 0.6;
}

/* ── Pinned messages modal items ── */
.cr-pinned-msg-item {
    padding: 10px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    margin-bottom: 6px;
    cursor: pointer;
    transition: background 0.15s;
}

.cr-pinned-msg-item:hover {
    background: rgba(251, 191, 36, 0.08);
}

.cr-pinned-msg-author {
    font-size: 12px;
    font-weight: 600;
    color: #fbbf24;
    margin-bottom: 3px;
}

.cr-pinned-msg-content {
    font-size: 14px;
    color: var(--text-primary, #f1f5f9);
    line-height: 1.4;
}

/* ── Message highlight (when scrolled to from pinned) ── */
.cr-msg-highlight .cr-msg-bubble {
    animation: crHighlight 2s ease;
}

@keyframes crHighlight {
    0%, 100% { box-shadow: none; }
    20%, 80% { box-shadow: 0 0 0 2px #fbbf24, 0 0 12px rgba(251, 191, 36, 0.3); }
}

/* Light mode */
.light-mode .cr-pinned-trigger {
    background: rgba(251, 191, 36, 0.06);
    border-color: rgba(251, 191, 36, 0.1);
}

.light-mode .cr-pinned-msg-item {
    background: rgba(0, 0, 0, 0.02);
}

/* ── Member dropdown menu (compact) ── */
.cr-member-menu-wrap {
    position: relative;
    flex-shrink: 0;
}

.cr-member-menu-btn {
    background: none;
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 6px;
    color: var(--text-secondary, #94a3b8);
    font-size: 16px;
    cursor: pointer;
    padding: 2px 8px;
    transition: all 0.15s;
}

.cr-member-menu-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary, #f1f5f9);
}

.cr-member-menu {
    position: fixed;
    background: #1e1e3a;
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 99999;
    padding: 4px;
    min-width: 150px;
}

.cr-member-menu.hidden {
    display: none;
}

.cr-mm-item {
    display: block;
    width: 100%;
    padding: 8px 12px;
    background: none;
    border: none;
    color: var(--text-secondary, #cbd5e1);
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
    text-align: left;
    transition: background 0.15s;
}

.cr-mm-item:hover {
    background: rgba(139, 92, 246, 0.1);
    color: var(--text-primary, #f1f5f9);
}

.cr-mm-item.cr-mm-danger {
    color: #f87171;
}

.cr-mm-item.cr-mm-danger:hover {
    background: rgba(248, 113, 113, 0.1);
}

.light-mode .cr-member-menu-btn {
    border-color: rgba(0, 0, 0, 0.1);
    color: #64748b;
}

.light-mode .cr-member-menu {
    background: #fff;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* ── System messages (join/leave/kick) ── */
.cr-msg-system {
    text-align: center;
    font-size: 12px;
    color: var(--text-secondary, #94a3b8);
    padding: 6px 12px;
    margin: 4px 0;
    opacity: 0.8;
}

/* ── Report modal ── */
.cr-report-reasons {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 12px;
}

.cr-report-reason-btn {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary, #cbd5e1);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.cr-report-reason-btn:hover {
    border-color: rgba(139, 92, 246, 0.3);
    background: rgba(139, 92, 246, 0.08);
}

.cr-report-reason-btn.active {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.15);
    color: #a78bfa;
}

.cr-report-input {
    width: 100%;
    padding: 10px 12px;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-primary, #f1f5f9);
    font-size: 13px;
    resize: none;
    outline: none;
    box-sizing: border-box;
}

.cr-report-input:focus {
    border-color: rgba(139, 92, 246, 0.4);
}

.cr-report-input::placeholder {
    color: var(--text-secondary, #94a3b8);
}

.light-mode .cr-report-reason-btn {
    border-color: rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.03);
    color: #4b5563;
}
.light-mode .cr-report-reason-btn.active {
    border-color: #8b5cf6;
    background: rgba(139, 92, 246, 0.08);
    color: #7c3aed;
}
.light-mode .cr-report-input {
    border-color: rgba(0, 0, 0, 0.1);
    background: rgba(0, 0, 0, 0.03);
    color: #1e293b;
}

/* ── Room info panel ── */
.cr-info-icon {
    font-size: 48px;
    text-align: center;
    margin-bottom: 8px;
}

.cr-info-name {
    font-size: 20px;
    font-weight: 700;
    color: var(--text-primary, #f1f5f9);
    text-align: center;
    margin-bottom: 20px;
}

.cr-info-grid {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.cr-info-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 12px;
    background: rgba(255, 255, 255, 0.03);
    border-radius: 8px;
}

.cr-info-label {
    font-size: 13px;
    color: var(--text-secondary, #94a3b8);
}

.cr-info-value {
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary, #f1f5f9);
}

.cr-info-edit-row {
    margin-bottom: 10px;
}

.cr-info-edit-row label {
    display: block;
    font-size: 12px;
    color: var(--text-secondary, #94a3b8);
    margin-bottom: 4px;
}

.cr-info-edit-row select.cr-input {
    appearance: auto;
    color: var(--text-primary, #f1f5f9);
    background: rgba(15, 15, 30, 0.8);
}

.cr-info-edit-row select.cr-input option {
    background: #1e1e3a;
    color: #f1f5f9;
}

.light-mode .cr-info-edit-row select.cr-input {
    background: #fff;
    color: #1e293b;
}

.light-mode .cr-info-edit-row select.cr-input option {
    background: #fff;
    color: #1e293b;
}

.light-mode .cr-info-row {
    background: rgba(0, 0, 0, 0.03);
}

/* ── Header more menu ── */
.cr-header-more-wrap {
    position: relative;
}

.cr-header-menu {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: #1e1e3a;
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
    z-index: 200;
    padding: 4px;
    min-width: 180px;
}

.cr-header-menu.hidden {
    display: none;
}

.cr-hm-item {
    display: block;
    width: 100%;
    padding: 9px 14px;
    background: none;
    border: none;
    color: var(--text-secondary, #cbd5e1);
    font-size: 13px;
    cursor: pointer;
    border-radius: 6px;
    text-align: left;
    transition: background 0.15s;
}

.cr-hm-item:hover {
    background: rgba(139, 92, 246, 0.1);
    color: var(--text-primary, #f1f5f9);
}

.cr-hm-item.cr-hm-danger {
    color: #f87171;
}

.cr-hm-item.cr-hm-danger:hover {
    background: rgba(248, 113, 113, 0.1);
}

.light-mode .cr-header-menu {
    background: #fff;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

/* ── Custom scrollbar for chat ── */
.cr-messages-area::-webkit-scrollbar {
    width: 6px;
}

.cr-messages-area::-webkit-scrollbar-track {
    background: transparent;
}

.cr-messages-area::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.3);
    border-radius: 3px;
}

.cr-messages-area::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.5);
}

.cr-messages-area {
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 92, 246, 0.3) transparent;
}

.light-mode .cr-messages-area::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.2);
}

.light-mode .cr-messages-area::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.4);
}

.light-mode .cr-messages-area {
    scrollbar-color: rgba(139, 92, 246, 0.2) transparent;
}

/* ── Modal scrollbar (thin, purple) ── */
.cr-modal::-webkit-scrollbar {
    width: 5px;
}

.cr-modal::-webkit-scrollbar-track {
    background: transparent;
}

.cr-modal::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.25);
    border-radius: 3px;
}

.cr-modal::-webkit-scrollbar-thumb:hover {
    background: rgba(139, 92, 246, 0.45);
}

.cr-modal {
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 92, 246, 0.25) transparent;
}

/* ── Dark select for transfer/settings ── */
.cr-select-dark {
    appearance: auto;
    background: rgba(15, 15, 30, 0.8) !important;
    color: var(--text-primary, #f1f5f9) !important;
}

.cr-select-dark option {
    background: #1e1e3a;
    color: #f1f5f9;
}

.light-mode .cr-select-dark {
    background: #f8fafc !important;
    color: #1e293b !important;
}

.light-mode .cr-select-dark option {
    background: #fff;
    color: #1e293b;
}

.light-mode .cr-modal::-webkit-scrollbar-thumb {
    background: rgba(139, 92, 246, 0.2);
}

.light-mode .cr-modal {
    scrollbar-color: rgba(139, 92, 246, 0.2) transparent;
}

/* ── Typing indicator ── */
.cr-typing-indicator {
    padding: 4px 16px;
    font-size: 12px;
    color: var(--text-secondary, #94a3b8);
    font-style: italic;
    flex-shrink: 0;
}

/* ── Online dot ── */
.cr-online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #10b981;
    border-radius: 50%;
    margin-right: 2px;
    animation: crOnlinePulse 2s infinite;
}

@keyframes crOnlinePulse {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.5; }
}

/* ── Online dot on chat message avatars ── */
.cr-msg-avatar.cr-avatar-online::after {
    content: '';
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #10b981;
    border: 2px solid var(--card-bg, #1e1b2e);
    border-radius: 50%;
}

.cr-msg-avatar {
    position: relative;
}

/* ── Offline dot (hidden mode) ── */
.cr-offline-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    background: #64748b;
    border-radius: 50%;
    margin-right: 2px;
}

/* ── Member panel online dot ── */
.cr-member-av-wrap {
    position: relative;
    display: inline-flex;
    flex-shrink: 0;
}

.cr-member-online-dot {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 10px;
    height: 10px;
    background: #10b981;
    border: 2px solid var(--card-bg, #1e1b2e);
    border-radius: 50%;
    z-index: 1;
}

.light-mode .cr-msg-avatar.cr-avatar-online::after {
    border-color: #fff;
}

.light-mode .cr-member-online-dot {
    border-color: #fff;
}

/* ── Emoji Picker ── */
.cr-emoji-wrap {
    position: relative;
}

.cr-emoji-picker {
    position: absolute;
    bottom: calc(100% + 8px);
    left: 0;
    width: 280px;
    background: #1e1e3a;
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    z-index: 9999;
    overflow: hidden;
}

.cr-emoji-picker.hidden {
    display: none;
}

.cr-emoji-tabs {
    display: flex;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    padding: 4px;
    gap: 2px;
}

.cr-emoji-tab {
    flex: 1;
    padding: 6px;
    background: none;
    border: none;
    border-radius: 6px;
    font-size: 16px;
    cursor: pointer;
    transition: background 0.15s;
}

.cr-emoji-tab:hover {
    background: rgba(255, 255, 255, 0.08);
}

.cr-emoji-tab.active {
    background: rgba(139, 92, 246, 0.2);
}

.cr-emoji-grid {
    display: grid;
    grid-template-columns: repeat(7, 1fr);
    gap: 2px;
    padding: 8px;
    max-height: 200px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: rgba(139, 92, 246, 0.2) transparent;
}

.cr-emoji-item {
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    transition: background 0.15s, transform 0.1s;
}

.cr-emoji-item:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: scale(1.2);
}

.light-mode .cr-emoji-picker {
    background: #fff;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
}

.light-mode .cr-emoji-tab.active {
    background: rgba(139, 92, 246, 0.1);
}

.light-mode .cr-emoji-item:hover {
    background: rgba(0, 0, 0, 0.06);
}

/* ── Scroll to bottom button ── */
.cr-scroll-bottom-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 8px;
    background: rgba(139, 92, 246, 0.12);
    border: none;
    border-top: 1px solid rgba(139, 92, 246, 0.2);
    color: #a78bfa;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
    transition: background 0.15s;
}

.cr-scroll-bottom-btn:hover {
    background: rgba(139, 92, 246, 0.2);
}

.cr-scroll-bottom-btn.hidden {
    display: none;
}

/* ── Lock chat member picker ── */
.cr-lock-members-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 250px;
    overflow-y: auto;
}

.cr-lock-member {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.03);
    cursor: pointer;
    transition: background 0.15s;
}

.cr-lock-member:hover {
    background: rgba(139, 92, 246, 0.08);
}

.cr-lock-member input[type="checkbox"] {
    accent-color: #8b5cf6;
    width: 16px;
    height: 16px;
}

.cr-lock-member span {
    font-size: 14px;
    color: var(--text-primary, #f1f5f9);
}

.light-mode .cr-lock-member {
    background: rgba(0, 0, 0, 0.02);
}

/* ── Unread badge on room card ── */
.cr-room-unread {
    background: #ef4444;
    color: #fff;
    font-size: 11px;
    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;
}

/* ── Unread badge on header menu item ── */
.cr-header-unread-badge {
    background: #ef4444;
    color: #fff;
    font-size: 10px;
    font-weight: 700;
    min-width: 16px;
    height: 16px;
    border-radius: 8px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0 4px;
    margin-left: 8px;
}

/* ── @Mention highlight ── */
.cr-mention {
    color: #a78bfa;
    font-weight: 600;
    background: rgba(139, 92, 246, 0.1);
    padding: 1px 4px;
    border-radius: 4px;
}

.cr-msg-own .cr-mention {
    color: #e9d5ff;
    background: rgba(255, 255, 255, 0.15);
}

/* ── Mention autocomplete dropdown ── */
.cr-mention-dropdown {
    position: absolute;
    bottom: 100%;
    left: 0;
    right: 0;
    background: #1e1e3a;
    border: 1px solid rgba(139, 92, 246, 0.2);
    border-radius: 10px;
    box-shadow: 0 -4px 16px rgba(0, 0, 0, 0.4);
    z-index: 9999;
    padding: 4px;
    margin-bottom: 4px;
}

.cr-mention-item {
    padding: 8px 12px;
    font-size: 13px;
    color: var(--text-primary, #f1f5f9);
    cursor: pointer;
    border-radius: 6px;
    transition: background 0.15s;
}

.cr-mention-item:hover {
    background: rgba(139, 92, 246, 0.15);
}

.light-mode .cr-mention-dropdown {
    background: #fff;
    border-color: rgba(0, 0, 0, 0.1);
    box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15);
}

.light-mode .cr-mention {
    color: #7c3aed;
    background: rgba(139, 92, 246, 0.08);
}

/* ── User profile modal ── */
.cr-profile-av-wrap {
    margin-bottom: 12px;
}

.cr-profile-avatar-img {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    object-fit: cover;
}

.cr-profile-avatar {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 28px;
    font-weight: 700;
    color: #fff;
}

.cr-profile-name {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary, #f1f5f9);
    margin-bottom: 4px;
}

.cr-profile-meta {
    font-size: 13px;
    color: var(--text-secondary, #94a3b8);
}


/* Message send status */
.cr-msg-status { font-size: 10px; margin-left: 4px; }
.cr-msg-sending { color: rgba(255,255,255,0.7); animation: crPulse 1s infinite; }
.cr-msg-sent { color: rgba(255,255,255,0.85); }
.cr-msg-failed { color: #fca5a5; cursor: pointer; }
@keyframes crPulse { 0%,100% { opacity: 1; } 50% { opacity: 0.4; } }


/* Chat loading indicator */
.cr-loading-chat { display: flex; flex-direction: column; align-items: center; justify-content: center; height: 200px; gap: 12px; }
.cr-loading-chat p { font-size: 13px; color: var(--text-secondary, #94a3b8); margin: 0; }
.cr-loading-dots { display: flex; gap: 6px; }
.cr-loading-dots span { width: 8px; height: 8px; border-radius: 50%; background: #8b5cf6; animation: crDotBounce 1.2s infinite; }
.cr-loading-dots span:nth-child(2) { animation-delay: 0.2s; }
.cr-loading-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes crDotBounce { 0%,80%,100% { transform: scale(0.6); opacity: 0.4; } 40% { transform: scale(1); opacity: 1; } }


/* Chat Search */
.cr-search-panel { padding: 8px 12px; border-bottom: 1px solid rgba(255,255,255,0.06); background: rgba(15,15,30,0.5); }
.cr-search-input-wrap { display: flex; gap: 8px; align-items: center; }
.cr-search-input { flex: 1; padding: 8px 12px; border-radius: 8px; border: 1px solid rgba(255,255,255,0.1); background: rgba(255,255,255,0.04); color: var(--text-primary, #f1f5f9); font-size: 13px; outline: none; }
.cr-search-input:focus { border-color: rgba(139,92,246,0.4); }
.cr-search-close { background: none; border: none; color: var(--text-secondary, #94a3b8); font-size: 16px; cursor: pointer; padding: 4px; }
.cr-search-results { max-height: 200px; overflow-y: auto; margin-top: 6px; }
.cr-search-result { padding: 8px 10px; border-radius: 6px; cursor: pointer; transition: background 0.15s; }
.cr-search-result:hover { background: rgba(139,92,246,0.08); }
.cr-search-result-name { font-size: 11px; color: var(--text-secondary, #94a3b8); margin-bottom: 2px; }
.cr-search-result-name span { color: var(--text-muted, #64748b); }
.cr-search-result-text { font-size: 13px; color: var(--text-primary, #f1f5f9); }
.cr-search-result-text mark { background: rgba(251,191,36,0.3); color: inherit; border-radius: 2px; padding: 0 2px; }
.cr-search-hint { font-size: 12px; color: var(--text-secondary, #94a3b8); text-align: center; padding: 12px; }
.cr-msg-highlight { animation: crHighlight 2s ease; }
@keyframes crHighlight { 0%,30% { background: rgba(139,92,246,0.15); } 100% { background: transparent; } }

.light-mode .cr-search-panel { background: rgba(248,250,252,0.9); border-bottom-color: rgba(0,0,0,0.06); }
.light-mode .cr-search-input { background: #fff; border-color: rgba(0,0,0,0.1); color: #1e293b; }
.light-mode .cr-search-result:hover { background: rgba(139,92,246,0.04); }
.light-mode .cr-search-result-text { color: #1e293b; }
