/* Chat Interface */

/* Image optimization */
img {
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.message-avatar img,
.friend-avatar img,
.group-avatar img,
.chat-avatar img,
.user-avatar-large img,
.menu-avatar img {
    will-change: auto;
    contain: layout style paint;
}

.chat-page {
    display: flex;
    height: 100vh;
    background: var(--bg-dark);
}

.sidebar {
    width: 320px;
    background: rgba(42, 42, 42, 0.8);
    backdrop-filter: blur(10px);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
    min-width: 0;
}

.user-avatar-large {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.user-details {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
    min-width: 0;
}

.username {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.user-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.8rem;
    color: var(--text-muted);
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.status-dot.online {
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
}

.menu-container {
    position: relative;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-open-menu {
    padding: 0.625rem 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    white-space: nowrap;
}

.btn-open-menu:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(102, 126, 234, 0.3);
}

/* Slide-out Menu Panel */
.slide-menu {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(32, 32, 32, 0.98);
    backdrop-filter: blur(10px);
    z-index: 100;
    transform: translateX(0);
    transition: transform 0.3s ease;
    display: flex;
    flex-direction: column;
}

.slide-menu.hidden {
    transform: translateX(-100%);
}

.slide-menu-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.slide-menu-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-close-menu {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.btn-close-menu:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

.slide-menu-content {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
}

.menu-user-card {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border-radius: var(--radius-md);
    margin-bottom: 1rem;
}

.menu-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.1rem;
    flex-shrink: 0;
}

.menu-user-details {
    flex: 1;
    min-width: 0;
}

.menu-username {
    font-weight: 600;
    font-size: 0.95rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.menu-user-tag {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.menu-divider {
    height: 1px;
    background: var(--border);
    margin: 0.5rem 0;
}

.menu-items {
    padding: 0.5rem;
}

.menu-item {
    width: 100%;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.75rem;
    background: transparent;
    border: none;
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.menu-item:hover {
    background: rgba(255, 255, 255, 0.08);
    color: white;
}

.menu-item svg {
    flex-shrink: 0;
    opacity: 0.7;
}

.menu-item:hover svg {
    opacity: 1;
}

.menu-item-danger {
    color: #ef4444;
}

.menu-item-danger:hover {
    background: rgba(239, 68, 68, 0.1);
    color: #f87171;
}

.icon-btn {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.5rem;
    border-radius: 4px;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: #444;
    color: white;
}

.icon-btn svg {
    display: block;
}

.sidebar-search {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
}

.search-input {
    width: 100%;
    padding: 0.75rem 1rem;
    background: rgba(26, 26, 26, 0.5);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.9rem;
    transition: all 0.3s;
}

.search-input:focus {
    outline: none;
    border-color: var(--primary);
    background: rgba(26, 26, 26, 0.8);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
}

.section-header {
    padding: 0.5rem 1rem;
    margin-bottom: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    min-height: 0;
}

.section-header+.list-container {
    margin-top: 0 !important;
    padding-top: 0 !important;
}

.list-container {
    display: none;
    padding: 0;
    margin: 0;
    min-height: 0;
}

.list-container.active {
    display: block;
}

.section-tabs {
    display: flex;
    gap: 0.5rem;
}

.section-tab {
    padding: 0.5rem 1rem;
    background: transparent;
    border: none;
    color: var(--text-muted);
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: all 0.2s;
}

.section-tab:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-secondary);
}

.section-tab.active {
    background: rgba(102, 126, 234, 0.15);
    color: var(--primary);
}

.btn-add {
    padding: 0.5rem 1rem;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.25rem;
    transition: all 0.3s;
}

.btn-add:hover {
    background: var(--primary-dark);
    transform: translateY(-2px);
    box-shadow: var(--shadow-sm);
}

.list-container {
    padding: 0.5rem;
    display: none;
}

.list-container.active {
    display: block;
}

.empty-state,
.welcome-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 2rem 1rem;
    text-align: center;
    color: var(--text-muted);
    min-height: 0;
}

.empty-state svg,
.welcome-state svg {
    margin-bottom: 1.5rem;
}

.empty-state p,
.welcome-state h3 {
    margin-bottom: 0.5rem;
    color: var(--text-secondary);
}

.empty-state small,
.welcome-state p {
    font-size: 0.9rem;
    color: #666;
}

.friend-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: var(--radius-md);
    margin-bottom: 0.25rem;
}

.friend-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.friend-item.active {
    background: rgba(102, 126, 234, 0.2);
}

.friend-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    flex-shrink: 0;
}

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

.friend-name {
    font-weight: 600;
    font-size: 0.9rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.friend-status {
    font-size: 0.8rem;
    color: var(--text-muted);
    text-transform: capitalize;
}

.friend-status.online {
    color: #4ade80;
}

.chat-main {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.chat-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    background: var(--bg-card);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-info {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem;
    border-radius: var(--radius-md);
    transition: background 0.2s;
}

.chat-info:hover {
    background: rgba(255, 255, 255, 0.05);
}

.chat-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
}

.chat-details {
    display: flex;
    flex-direction: column;
}

.chat-name {
    font-weight: 600;
}

.chat-status {
    font-size: 0.85rem;
    color: var(--text-muted);
}

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

.messages {
    flex: 1;
    overflow-y: auto;
    padding: 1rem;
    padding-top: 4rem; /* Space for connection status */
    display: flex;
    flex-direction: column;
    gap: 1rem;
    position: relative;
}

.message {
    display: flex;
    gap: 0.75rem;
    padding: 0.5rem;
    margin: -0.5rem;
    border-radius: 8px;
    transition: background 0.2s;
    position: relative;
}

.message:hover {
    background: rgba(255, 255, 255, 0.05);
}

.message-context-menu {
    position: absolute;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    padding: 0.5rem 0;
    min-width: 150px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 1000;
}

.message-context-menu-item {
    padding: 0.75rem 1rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: white;
    transition: background 0.2s;
}

.message-context-menu-item:hover {
    background: rgba(255, 255, 255, 0.1);
}

.message-context-menu-item.danger {
    color: #ef4444;
}

.message-context-menu-item.danger:hover {
    background: rgba(239, 68, 68, 0.1);
}

.message-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: var(--primary);
    flex-shrink: 0;
}

.message-content {
    flex: 1;
}

.message-header {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
}

.message-author {
    font-weight: 600;
    font-size: 0.9rem;
    display: flex;
    align-items: center;
    gap: 0.25rem;
}

.encrypted-icon {
    color: #4ade80;
    opacity: 0.7;
    flex-shrink: 0;
    cursor: pointer;
    position: relative;
}

.encrypted-icon:hover {
    opacity: 1;
}

.encrypted-icon:hover::after {
    content: 'End-to-end encrypted';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    z-index: 1000;
    margin-bottom: 0.5rem;
    pointer-events: none;
}

.encrypted-icon:hover::before {
    content: '';
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    border: 5px solid transparent;
    border-top-color: rgba(0, 0, 0, 0.9);
    margin-bottom: 0.25rem;
    pointer-events: none;
}

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

.message-text {
    line-height: 1.4;
    word-wrap: break-word;
    overflow-wrap: break-word;
}

.message-text.encrypted-error {
    color: var(--text-muted);
    font-style: italic;
}

.message-gif-embed {
    margin-top: 0.5rem;
    border-radius: 8px;
    overflow: hidden;
    max-width: 300px;
}

.message-gif-embed img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 8px;
}

.chat-status .status-dot {
    display: inline-block;
    margin-right: 0.25rem;
}

.message-input-container {
    padding: 1rem;
    border-top: 1px solid var(--border);
    background: var(--bg-card);
    display: flex;
    gap: 0.5rem;
}

.message-input-wrapper {
    flex: 1;
}

.message-input-wrapper input {
    width: 100%;
}

.btn-send {
    padding: 0.75rem 1.5rem;
    background: var(--primary);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-send:hover:not(:disabled) {
    background: var(--primary-dark);
}

.btn-send:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        max-width: 300px;
        position: absolute;
        left: -100%;
        transition: left 0.3s;
        z-index: 100;
    }

    .sidebar.open {
        left: 0;
    }
}


/* Groups Styling */
.group-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    cursor: pointer;
    transition: all 0.2s;
    border-radius: 8px;
    margin-bottom: 0.25rem;
}

.group-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.group-item.active {
    background: rgba(102, 126, 234, 0.2);
}

.group-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 600;
    font-size: 1.1rem;
    color: white;
    flex-shrink: 0;
}

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

.group-name {
    font-weight: 600;
    margin-bottom: 0.25rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: white;
}

.group-members {
    font-size: 0.85rem;
    color: #888;
}

/* Friend Checkbox in Group Creation */
.friend-checkbox {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.75rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
}

.friend-checkbox:hover {
    background: rgba(255, 255, 255, 0.05);
}

.friend-checkbox input[type="checkbox"] {
    width: 18px;
    height: 18px;
    cursor: pointer;
}

/* Modal Textarea */
.modal-body textarea {
    width: 100%;
    padding: 0.75rem;
    background: rgba(26, 26, 26, 0.5);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    font-family: inherit;
    resize: vertical;
    min-height: 80px;
}

.modal-body textarea:focus {
    outline: none;
    border-color: #667eea;
    background: rgba(26, 26, 26, 0.8);
}

#member-selection {
    max-height: 200px;
    overflow-y: auto;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    padding: 0.5rem;
    background: rgba(26, 26, 26, 0.3);
}


/* Group Settings */
.group-settings-section {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.group-settings-section h3 {
    font-size: 0.9rem;
    color: #888;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 0.5rem;
}

.settings-option-btn {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: white;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.settings-option-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #667eea;
}

.settings-option-btn.danger {
    color: #ef4444;
}

.settings-option-btn.danger:hover {
    background: rgba(239, 68, 68, 0.1);
    border-color: #ef4444;
}

.settings-option-btn svg {
    flex-shrink: 0;
}


/* Invite Options */
.invite-options {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.invite-option-btn {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 8px;
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    text-align: left;
}

.invite-option-btn:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: #667eea;
    transform: translateY(-2px);
}

.invite-option-btn svg {
    flex-shrink: 0;
    color: #667eea;
}

.option-title {
    font-weight: 600;
    font-size: 1rem;
    margin-bottom: 0.25rem;
}

.option-desc {
    font-size: 0.85rem;
    color: #888;
}

/* Friend Invite List */
.friend-invite-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem;
    cursor: pointer;
    border-radius: 8px;
    transition: background 0.2s;
    border: 1px solid rgba(255, 255, 255, 0.08);
    margin-bottom: 0.5rem;
}

.friend-invite-item:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: #667eea;
}

.friend-tag {
    font-size: 0.85rem;
    color: #888;
}

#friend-list-invite {
    max-height: 300px;
    overflow-y: auto;
    margin-top: 1rem;
}


/* Group Invite Card */
.invite-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 8px;
    padding: 0.75rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    max-width: 350px;
    margin-top: 0.5rem;
}

.invite-card-content {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    flex: 1;
}

.invite-group-avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #667eea;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.1rem;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

.invite-group-info {
    flex: 1;
}

.invite-group-name {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 0.125rem;
    color: white;
}

.invite-group-members {
    font-size: 0.8rem;
    color: #888;
}

.invite-join-btn {
    padding: 0.5rem 1.25rem;
    background: #10b981;
    border: none;
    border-radius: 6px;
    color: white;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    flex-shrink: 0;
}

.invite-join-btn:hover {
    background: #059669;
    transform: translateY(-1px);
}


/* System Friend (DogeGage) Styling */
.system-friend {
    background: rgba(59, 130, 246, 0.1);
    border: 1px solid rgba(59, 130, 246, 0.2);
}

.system-friend:hover {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.3);
}

.system-friend.active {
    background: rgba(59, 130, 246, 0.25);
    border-color: rgba(59, 130, 246, 0.4);
}

.system-friend .friend-avatar {
    background: white;
    padding: 0;
}

.system-friend .friend-avatar img {
    object-fit: cover !important;
}

.friend-profile-avatar.system-avatar {
    background: white;
    padding: 0;
}

.friend-profile-avatar.system-avatar img {
    object-fit: cover !important;
}

/* Mobile Responsive Styles */
@media (max-width: 768px) {
    .chat-page {
        position: relative;
        overflow: hidden;
        height: 100vh;
        height: 100dvh; /* Dynamic viewport height for mobile browsers */
    }

    .sidebar {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        max-width: 100%;
        height: 100%;
        border-right: none;
        z-index: 10;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        transform: translateX(0);
    }

    .chat-main {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        z-index: 5;
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
        transform: translateX(100%);
    }

    /* When a chat is active, show chat and hide sidebar */
    .chat-page.chat-active .sidebar {
        transform: translateX(-100%);
    }

    .chat-page.chat-active .chat-main {
        transform: translateX(0);
    }

    /* Prevent body scroll on mobile */
    body.chat-open {
        overflow: hidden;
        position: fixed;
        width: 100%;
        height: 100%;
    }

    .sidebar-header {
        padding: 0.875rem;
        min-height: 60px;
    }

    .user-avatar-large {
        width: 38px;
        height: 38px;
        font-size: 1rem;
    }

    .btn-open-menu {
        padding: 0.5rem 0.875rem;
        font-size: 0.8rem;
        white-space: nowrap;
    }

    .username {
        font-size: 0.875rem;
    }

    .user-status {
        font-size: 0.75rem;
    }

    .sidebar-search {
        padding: 0.75rem;
    }

    .search-input {
        padding: 0.625rem 0.875rem;
        font-size: 0.85rem;
    }

    .section-header {
        padding: 0.5rem 0.75rem;
    }

    .section-tab {
        padding: 0.4rem 0.75rem;
        font-size: 0.85rem;
    }

    .friend-item,
    .group-item {
        padding: 0.75rem;
    }

    .friend-avatar,
    .group-avatar {
        width: 40px;
        height: 40px;
        font-size: 1rem;
    }

    .friend-name,
    .group-name {
        font-size: 0.9rem;
    }

    .friend-status,
    .group-members {
        font-size: 0.75rem;
    }

    .chat-header {
        padding: 0.875rem;
        min-height: 60px;
        flex-wrap: nowrap;
    }

    .chat-info {
        padding: 0.25rem;
        min-width: 0;
        flex: 1;
    }

    .chat-avatar {
        width: 38px;
        height: 38px;
        font-size: 0.95rem;
    }

    .chat-name {
        font-size: 0.95rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chat-status {
        font-size: 0.75rem;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .chat-actions {
        gap: 0.25rem;
        flex-shrink: 0;
    }

    .icon-btn {
        padding: 0.5rem;
        min-width: 36px;
        min-height: 36px;
    }

    .icon-btn svg {
        width: 20px;
        height: 20px;
    }

    .messages {
        padding: 0.875rem;
        gap: 0.875rem;
    }

    .message {
        gap: 0.625rem;
        padding: 0.5rem;
        margin: -0.5rem;
    }

    .message-avatar {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

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

    .message-header {
        gap: 0.5rem;
        flex-wrap: wrap;
    }

    .message-author {
        font-size: 0.875rem;
    }

    .message-time {
        font-size: 0.7rem;
    }

    .message-text {
        font-size: 0.9375rem;
        line-height: 1.5;
        word-break: break-word;
    }

    .encrypted-icon svg {
        width: 11px;
        height: 11px;
    }

    .message-input-container {
        padding: 0.875rem;
        gap: 0.625rem;
        min-height: 60px;
    }

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

    #message-input {
        padding: 0.75rem 1rem;
        font-size: 1rem; /* 16px to prevent zoom on iOS */
        border-radius: 20px;
    }

    .btn-send {
        padding: 0.75rem 1.25rem;
        font-size: 0.9rem;
        border-radius: 20px;
        flex-shrink: 0;
    }

    .modal-overlay {
        padding: 0;
        align-items: flex-end;
    }

    .modal-content {
        width: 100%;
        max-width: 100%;
        margin: 0;
        padding: 1.5rem;
        border-radius: 20px 20px 0 0;
        max-height: 90vh;
        overflow-y: auto;
    }

    .modal-content h2 {
        font-size: 1.25rem;
    }

    .modal-header {
        margin-bottom: 1.25rem;
    }

    .modal-close {
        font-size: 1.75rem;
        padding: 0.25rem;
    }

    .input-group {
        margin-bottom: 1.25rem;
    }

    .input-group label {
        font-size: 0.875rem;
        margin-bottom: 0.5rem;
    }

    .input-group input,
    .input-group textarea,
    .input-group select {
        padding: 0.75rem 1rem;
        font-size: 1rem; /* 16px to prevent zoom on iOS */
        border-radius: 12px;
    }

    .input-group textarea {
        min-height: 100px;
    }

    .modal-footer {
        gap: 0.75rem;
        margin-top: 1.5rem;
    }

    .btn-primary,
    .btn-secondary,
    .btn-cancel {
        padding: 0.875rem 1.25rem;
        font-size: 1rem;
        border-radius: 12px;
        flex: 1;
    }

    .invite-card {
        max-width: 100%;
        padding: 1rem;
    }

    .invite-card-content {
        gap: 0.875rem;
    }

    .invite-group-avatar {
        width: 48px;
        height: 48px;
        font-size: 1.25rem;
    }

    .invite-group-name {
        font-size: 1rem;
    }

    .invite-join-btn {
        padding: 0.75rem 1.5rem;
        font-size: 0.9375rem;
        white-space: nowrap;
    }

    /* Settings options */
    .settings-option-btn {
        padding: 1rem;
        font-size: 0.9375rem;
    }

    .settings-option-btn svg {
        width: 20px;
        height: 20px;
    }

    /* Invite options */
    .invite-option-btn {
        padding: 1.125rem;
    }

    .option-title {
        font-size: 0.9375rem;
    }

    .option-desc {
        font-size: 0.8125rem;
    }

    /* Friend selection */
    .friend-checkbox {
        padding: 0.875rem;
    }

    .friend-checkbox input[type="checkbox"] {
        width: 20px;
        height: 20px;
    }

    /* Empty states */
    .empty-state,
    .welcome-state {
        padding: 3rem 1.5rem;
    }

    .empty-state svg,
    .welcome-state svg {
        width: 56px;
        height: 56px;
    }

    .empty-state p,
    .welcome-state h3 {
        font-size: 1.125rem;
    }

    .empty-state small,
    .welcome-state p {
        font-size: 0.875rem;
    }

    /* Context menu */
    .message-context-menu {
        min-width: 180px;
        border-radius: 12px;
    }

    .message-context-menu-item {
        padding: 0.875rem 1.125rem;
        font-size: 0.9375rem;
    }

    /* Slide menu */
    .slide-menu-header {
        padding: 0.875rem;
        min-height: 60px;
    }

    .slide-menu-content {
        padding: 1rem;
    }

    .menu-user-card {
        padding: 1rem;
        margin-bottom: 1.25rem;
    }

    .menu-item {
        padding: 0.75rem 0.875rem;
        font-size: 0.9375rem;
    }

    /* Prevent text selection on mobile for better UX */
    .friend-item,
    .group-item,
    .menu-item,
    .btn-open-menu,
    .icon-btn {
        -webkit-tap-highlight-color: transparent;
        user-select: none;
    }

    /* Improve touch targets */
    .friend-item,
    .group-item {
        min-height: 56px;
    }

    /* Safe area insets for notched devices */
    .chat-page {
        padding-bottom: env(safe-area-inset-bottom);
    }

    .sidebar-header,
    .chat-header {
        padding-top: max(0.875rem, env(safe-area-inset-top));
    }

    .message-input-container {
        padding-bottom: max(0.875rem, env(safe-area-inset-bottom));
    }
}

/* Mobile back button */
.btn-mobile-back {
    display: none;
    background: transparent;
    border: none;
    color: white;
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0.5rem;
    margin-right: 0.5rem;
    transition: all 0.2s;
    line-height: 1;
}

.btn-mobile-back:hover {
    color: var(--primary);
}

@media (max-width: 768px) {
    .btn-mobile-back {
        display: inline-flex;
        align-items: center;
        justify-content: center;
    }
}
/* 
Connection status indicator */
.connection-status {
    position: absolute;
    top: 1rem;
    right: 1rem;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    z-index: 10;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.connection-status-dot {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    animation: pulse 2s ease-in-out infinite;
}

.connection-status.websocket .connection-status-dot {
    background: #4ade80;
    box-shadow: 0 0 8px rgba(74, 222, 128, 0.5);
}

.connection-status.polling .connection-status-dot {
    background: #fbbf24;
    box-shadow: 0 0 8px rgba(251, 191, 36, 0.5);
}

.connection-status.disconnected .connection-status-dot {
    background: #ef4444;
    box-shadow: 0 0 8px rgba(239, 68, 68, 0.5);
    animation: none;
}

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

/* Notification bell and badge */
#notification-bell {
    position: relative;
}

.notification-badge {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 0.15rem 0.35rem;
    border-radius: 10px;
    min-width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: 0 2px 8px rgba(239, 68, 68, 0.4);
    animation: badge-pulse 2s ease-in-out infinite;
}

@keyframes badge-pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.1);
    }
}

/* Unread badge on friend items */
.unread-badge {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: #ef4444;
    color: white;
    font-size: 0.7rem;
    font-weight: 700;
    padding: 0.2rem 0.4rem;
    border-radius: 10px;
    min-width: 20px;
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Notification dropdown */
.notification-dropdown {
    position: absolute;
    top: calc(100% + 0.5rem);
    right: 0;
    width: 360px;
    max-height: 480px;
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 12px;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    overflow: hidden;
    z-index: 1000;
    display: none;
}

.notification-dropdown.show {
    display: block;
    animation: slideDown 0.2s ease-out;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.notification-dropdown-header {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.notification-dropdown-header h3 {
    font-size: 1rem;
    font-weight: 600;
    margin: 0;
}

.notification-list {
    max-height: 400px;
    overflow-y: auto;
}

.notification-item {
    padding: 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s;
    display: flex;
    gap: 0.75rem;
}

.notification-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.notification-item:last-child {
    border-bottom: none;
}

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

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

.notification-content {
    flex: 1;
    min-width: 0;
}

.notification-from {
    font-weight: 600;
    font-size: 0.9rem;
    margin-bottom: 0.25rem;
}

.notification-preview {
    font-size: 0.85rem;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.notification-time {
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 0.25rem;
}

.notification-empty {
    padding: 3rem 1rem;
    text-align: center;
    color: var(--text-muted);
}

.notification-empty svg {
    opacity: 0.3;
    margin-bottom: 1rem;
}

/* Mobile notification bell */
.mobile-notification-bell {
    position: relative;
    display: none;
}

/* Show mobile bell on mobile, hide desktop bell */
@media (max-width: 768px) {
    .mobile-notification-bell {
        display: flex;
    }
    
    #notification-bell {
        display: none;
    }
}

/* Resync Banner */
.resync-banner,
.resync-success-banner {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid #ef4444;
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
    animation: slideDown 0.3s ease-out;
}

.resync-success-banner {
    background: rgba(34, 197, 94, 0.1);
    border-color: #22c55e;
}

.resync-banner-content {
    display: flex;
    align-items: flex-start;
    gap: 1rem;
}

.resync-banner-content svg {
    flex-shrink: 0;
    color: #ef4444;
    margin-top: 0.25rem;
}

.resync-success-banner svg {
    color: #22c55e;
}

.resync-banner-content > div {
    flex: 1;
}

.resync-banner-content strong {
    display: block;
    color: var(--text);
    margin-bottom: 0.25rem;
}

.resync-banner-content p {
    color: var(--text-secondary);
    font-size: 0.875rem;
    margin: 0;
}

.resync-banner-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: all 0.2s;
}

.resync-banner-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text);
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Pending and Failed Message States */
.message-pending {
    opacity: 0.6;
    transition: opacity 0.3s ease;
}

.message-pending .message-avatar,
.message-pending .message-author,
.message-pending .message-time,
.message-pending .message-text {
    opacity: 0.7;
}

.message-pending .message-text {
    color: #999;
}

.message-failed {
    opacity: 1;
}

.message-failed .message-text {
    color: #ef4444 !important;
}

.message-retry-btn {
    margin-top: 4px;
    padding: 4px 12px;
    background: #ef4444;
    color: white;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85em;
    font-weight: 500;
    transition: all 0.2s;
}

.message-retry-btn:hover {
    background: #dc2626;
    transform: translateY(-1px);
}

.message-retry-btn:active {
    transform: translateY(0);
}

/* Emoji Button - Inline in message input */
.message-input-wrapper {
    position: relative;
    flex: 1;
    display: flex;
    align-items: center;
}

.btn-emoji-inline {
    position: absolute;
    width: 32px;
    height: 32px;
    background: #374151;
    border: none;
    border-radius: 6px;
    font-size: 18px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 0;
}

#emoji-btn-inline {
    right: 8px;
}

#gif-btn-inline {
    right: 48px;
    font-size: 10px;
    font-weight: 700;
}

.btn-emoji-inline:hover:not(:disabled) {
    background: #4b5563;
    transform: scale(1.05);
}

.btn-emoji-inline:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#message-input {
    padding-right: 88px !important;
}
