/* All colors now use CSS variables, so dark mode works automatically */

.messenger-container {
    max-width: 920px;
    width: 100%;
    margin: 0 auto;
    padding: 0 1rem;
}

.room-setup {
    margin-bottom: 2rem;
}

.room-form {
    display: flex;
    gap: 1.25rem;
    flex-wrap: wrap;
}

.room-form input {
    flex: 1;
    min-width: 240px;
    padding: 1rem 1.25rem;
    border: 1.5px solid var(--border-color);
    border-radius: 12px;
    font-family: 'Inter', sans-serif;
    font-size: 1.0625rem;
    background: var(--bg-secondary);
    color: var(--text-primary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.room-form input:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow: 0 0 0 3px var(--shadow-color);
}

.room-form .btn-primary {
    padding: 1rem 2.25rem;
    border-radius: 12px;
    font-size: 1.0625rem;
    font-weight: 500;
    white-space: nowrap;
    margin-bottom: 0;
}

.messenger-layout {
    display: flex;
    gap: 1rem;
    height: calc(100vh - 12rem);
    min-height: 600px;
    max-height: 880px;
}

.rooms-sidebar {
    width: 250px;
    background: var(--bg-secondary);
    border-radius: 18px;
    border: 1px solid var(--border-color);
    padding: 1rem;
    display: none;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    transition: all 0.3s ease;
}

.rooms-sidebar.active {
    display: flex;
}

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

.rooms-sidebar-header h3 {
    margin: 0;
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.room-tab {
    padding: 0.75rem;
    background: var(--bg-primary);
    border-radius: 8px;
    border: 1px solid var(--border-color);
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.room-tab:hover {
    background: var(--bg-secondary);
    transform: translateX(2px);
}

.room-tab.active {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.room-tab-name {
    font-weight: 500;
    font-size: 0.875rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.room-tab-id {
    font-size: 0.75rem;
    font-family: monospace;
    opacity: 0.7;
    margin-top: 0.25rem;
}

.room-tab-close {
    background: none;
    border: none;
    color: inherit;
    cursor: pointer;
    padding: 0.25rem;
    opacity: 0.6;
    transition: opacity 0.2s ease;
}

.room-tab-close:hover {
    opacity: 1;
}

.chat-container {
    flex: 1;
    display: none;
    flex-direction: column;
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    border: 1px solid var(--border-color);
    transition: all 0.3s ease;
}

[data-theme="dark"] .chat-container {
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
}

.chat-container.active {
    display: flex;
}

.chat-header {
    background: var(--bg-secondary);
    padding: 1.125rem 1.5rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    flex-shrink: 0;
}

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

.room-id-display {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.75rem;
    color: var(--text-secondary);
    background: var(--bg-primary);
    padding: 0.4375rem 0.875rem;
    border-radius: 6px;
    transition: background-color 0.3s ease, color 0.3s ease;
    letter-spacing: 0.02em;
}

.connection-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.375rem 0.75rem;
    border-radius: 6px;
    background: var(--bg-primary);
    font-size: 0.75rem;
    transition: all 0.3s ease;
}

.connection-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    display: inline-block;
    animation: pulse 2s ease-in-out infinite;
}

.connection-indicator-connected {
    background: #4ade80;
    box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
}

.connection-indicator-connecting {
    background: #fbbf24;
    box-shadow: 0 0 0 0 rgba(251, 191, 36, 0.7);
}

.connection-indicator-disconnected {
    background: #ef4444;
    box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    animation: none;
}

@keyframes pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(74, 222, 128, 0.7);
    }
    70% {
        box-shadow: 0 0 0 4px rgba(74, 222, 128, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(74, 222, 128, 0);
    }
}

.connection-text {
    color: var(--text-secondary);
    font-size: 0.75rem;
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 1rem 1.5rem;
    background: var(--bg-primary);
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    transition: background-color 0.3s ease;
    scroll-behavior: smooth;
    min-height: 0;
}

/* Smooth scrollbar styling */
.messages-container::-webkit-scrollbar {
    width: 6px;
}

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

.messages-container::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

.messages-container::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
    opacity: 0.4;
}

.message {
    max-width: 65%;
    padding: 0.625rem 0.875rem 0.625rem 1rem;
    border-radius: 14px;
    word-wrap: break-word;
    animation: fadeIn 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
}

.message:hover {
    transform: translateY(-1px);
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12), 0 2px 6px rgba(0, 0, 0, 0.08);
}

.message.own {
    align-self: flex-end;
    background: linear-gradient(135deg, #2a2a2a 0%, #323232 50%, #2a2a2a 100%);
    border-radius: 16px 16px 4px 16px;
    transition: all 0.3s ease;
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.15), 0 1px 4px rgba(0, 0, 0, 0.1);
    border: 1px solid rgba(250, 249, 246, 0.05);
}

.message-avatar {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    font-size: 0.4375rem;
    font-weight: 700;
    flex-shrink: 0;
    margin-right: 0.375rem;
}

.message-avatar-own {
    background: rgba(250, 249, 246, 0.25);
    color: #faf9f6;
    border: 1px solid rgba(250, 249, 246, 0.15);
}

.message-avatar-other {
    background: var(--border-color);
    color: var(--text-primary);
    opacity: 0.8;
}

.message-sender-name {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.08em;
}

.message.own .message-header {
    color: #faf9f6;
    opacity: 0.85;
    font-size: 0.5rem;
    margin-bottom: 0.375rem;
    display: flex;
    align-items: center;
    line-height: 1.2;
}

.message.own .message-content {
    color: #faf9f6;
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    margin: 0;
    padding: 0;
    font-size: 0.9375rem;
    font-weight: 400;
    letter-spacing: 0.015em;
    text-rendering: optimizeLegibility;
}

.message.own .message-time {
    color: #faf9f6;
    opacity: 0.6;
    font-size: 0.5625rem;
    margin-top: 0.25rem;
    text-align: right;
    font-weight: 400;
    line-height: 1.2;
}

/* Dark mode for own messages */
[data-theme="dark"] .message.own {
    background: linear-gradient(135deg, #3a3a3a 0%, #424242 50%, #3a3a3a 100%);
    box-shadow: 0 3px 12px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.2);
    border-color: rgba(250, 249, 246, 0.08);
}

[data-theme="dark"] .message.own .message-header,
[data-theme="dark"] .message.own .message-content,
[data-theme="dark"] .message.own .message-time {
    color: #faf9f6;
}

.message.other {
    align-self: flex-start;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 14px 14px 14px 4px;
    transition: all 0.3s ease;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
}

.message.other .message-header {
    color: var(--text-primary);
    opacity: 0.75;
    font-size: 0.5rem;
    margin-bottom: 0.375rem;
    display: flex;
    align-items: center;
    line-height: 1.2;
}


.message.other .message-content {
    color: var(--text-primary);
    line-height: 1.65;
    white-space: pre-wrap;
    word-break: break-word;
    overflow-wrap: break-word;
    margin: 0;
    padding: 0;
    font-size: 0.9375rem;
    font-weight: 400;
    letter-spacing: 0.015em;
    text-rendering: optimizeLegibility;
}

.message.other .message-time {
    color: var(--text-secondary);
    opacity: 0.6;
    font-size: 0.5rem;
    margin-top: 0;
    font-weight: 400;
    line-height: 1.1;
}

.message-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-top: 0.5rem;
    gap: 0.5rem;
}

.message-encryption-toggle {
    background: transparent;
    border: none;
    padding: 0.25rem;
    cursor: pointer;
    opacity: 0.5;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    color: inherit;
}

.message.own .message-encryption-toggle {
    color: #faf9f6;
}

.message.other .message-encryption-toggle {
    color: var(--text-secondary);
}

.message-encryption-toggle:hover {
    opacity: 0.8;
    background: rgba(0, 0, 0, 0.05);
}

.message.own .message-encryption-toggle:hover {
    background: rgba(255, 255, 255, 0.1);
}

.message-encryption-toggle.active {
    opacity: 1;
}

.message-encryption-toggle svg {
    width: 12px;
    height: 12px;
}

.message-encryption-details {
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid;
    animation: slideDown 0.2s ease-out;
}

.message.own .message-encryption-details {
    border-color: rgba(250, 249, 246, 0.15);
}

.message.other .message-encryption-details {
    border-color: var(--border-color);
}

@keyframes slideDown {
    from {
        opacity: 0;
        max-height: 0;
    }
    to {
        opacity: 1;
        max-height: 500px;
    }
}

.encryption-details-content {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.375rem 0.75rem;
    font-size: 0.5rem;
}

.encryption-detail-item {
    display: flex;
    flex-direction: column;
    gap: 0.125rem;
}

.encryption-label {
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    opacity: 0.7;
    font-size: 0.4375rem;
}

.encryption-value {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.5rem;
    opacity: 0.9;
    word-break: break-word;
}

.message.own .encryption-label,
.message.own .encryption-value {
    color: #faf9f6;
}

.message.other .encryption-label,
.message.other .encryption-value {
    color: var(--text-primary);
}

@media (max-width: 480px) {
    .encryption-details-content {
        grid-template-columns: 1fr;
        gap: 0.5rem;
    }
}

/* QR Code Modal */
.qr-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease-out;
}

.qr-modal-content {
    background: var(--bg-primary);
    border-radius: 16px;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    animation: slideUp 0.3s ease-out;
}

.qr-modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.qr-modal-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.qr-modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.qr-modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.qr-modal-body {
    padding: 2rem;
    text-align: center;
}

#qrCodeContainer {
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 1rem;
    background: white;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

.message-content:empty {
    display: none;
}

/* Encryption Verification Modal */
.verification-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease-out;
}

.verification-modal-content {
    background: var(--bg-primary);
    border-radius: 16px;
    max-width: 700px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    animation: slideUp 0.3s ease-out;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.verification-modal-header {
    padding: 1.5rem 2rem;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.verification-modal-header h3 {
    margin: 0;
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
}

.verification-modal-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.verification-modal-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.verification-modal-body {
    padding: 2rem;
}

.verification-section {
    margin-bottom: 2rem;
}

.verification-section:last-child {
    margin-bottom: 0;
}

.verification-section-title {
    font-size: 1.125rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.verification-section-title svg {
    width: 18px;
    height: 18px;
    color: #4ade80;
}

.verification-test {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1.5rem;
    margin-bottom: 1rem;
}

.verification-test-item {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

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

.verification-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.verification-value {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.875rem;
    color: var(--text-primary);
    background: var(--bg-primary);
    padding: 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border-color);
    word-break: break-all;
    line-height: 1.6;
}

.verification-success {
    color: #4ade80;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.verification-success svg {
    width: 18px;
    height: 18px;
}

.verification-comparison {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-top: 1rem;
}

.verification-comparison-item {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 1rem;
}

.verification-comparison-item h4 {
    margin: 0 0 0.75rem 0;
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.verification-comparison-item .value {
    font-family: 'Monaco', 'Menlo', monospace;
    font-size: 0.75rem;
    color: var(--text-primary);
    word-break: break-all;
    line-height: 1.6;
}

.verification-loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

@media (max-width: 768px) {
    .verification-modal-content {
        width: 95%;
        max-height: 90vh;
    }
    
    .verification-modal-header {
        padding: 1.25rem 1.5rem;
    }
    
    .verification-modal-body {
        padding: 1.5rem;
    }
    
    .verification-comparison {
        grid-template-columns: 1fr;
    }
}

.chat-input-container {
    background: var(--bg-secondary);
    padding: 1.125rem 1.5rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    gap: 1rem;
    align-items: flex-end;
    transition: background-color 0.3s ease, border-color 0.3s ease;
    flex-shrink: 0;
}

.chat-input {
    flex: 1;
    padding: 0.875rem 1.25rem;
    border: 1px solid var(--border-color);
    border-radius: 14px;
    font-family: 'Inter', sans-serif;
    font-size: 0.9375rem;
    resize: none;
    background: var(--bg-primary);
    color: var(--text-primary);
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    min-height: 24px;
    max-height: 120px;
    line-height: 1.5;
    overflow-y: auto;
}

.chat-input::-webkit-scrollbar {
    width: 4px;
}

.chat-input::-webkit-scrollbar-track {
    background: transparent;
}

.chat-input::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 2px;
}

.chat-input::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
    opacity: 0.5;
}

.chat-input:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow: 0 0 0 3px var(--shadow-color);
}

.chat-input::placeholder {
    color: var(--text-secondary);
    opacity: 0.6;
    font-size: 0.9rem;
}

.send-btn {
    padding: 0.875rem 2rem;
    background: var(--button-bg);
    color: var(--button-text);
    border: none;
    border-radius: 14px;
    font-family: 'Merriweather', serif;
    font-size: 0.9375rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.send-btn:hover:not(:disabled) {
    opacity: 0.95;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.send-btn:active:not(:disabled) {
    transform: translateY(0);
    box-shadow: 0 1px 4px rgba(0, 0, 0, 0.1);
}

.send-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

/* Message animation */
@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px) scale(0.98);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message {
    animation: fadeIn 0.35s cubic-bezier(0.4, 0, 0.2, 1);
}

.empty-state {
    text-align: center;
    color: var(--text-secondary);
    opacity: 0.6;
    padding: 4rem 1rem;
    font-style: italic;
    font-size: 1rem;
    transition: color 0.3s ease;
}

/* Loading indicator */
.loading-indicator {
    text-align: center;
    padding: 1rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    opacity: 0.7;
}

.loading-indicator::after {
    content: '...';
    animation: dots 1.5s steps(4, end) infinite;
}

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

/* Typing indicator */
.typing-indicator {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem 1rem;
    margin: 0.5rem 0;
    background: var(--bg-secondary);
    border-radius: 12px;
    font-size: 0.875rem;
    color: var(--text-secondary);
    animation: fadeIn 0.3s ease-out;
}

.typing-dots {
    display: flex;
    gap: 0.25rem;
    align-items: center;
}

.typing-dots span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--text-secondary);
    opacity: 0.6;
    animation: typingDot 1.4s ease-in-out infinite;
}

.typing-dots span:nth-child(2) {
    animation-delay: 0.2s;
}

.typing-dots span:nth-child(3) {
    animation-delay: 0.4s;
}

@keyframes typingDot {
    0%, 60%, 100% {
        transform: translateY(0);
        opacity: 0.6;
    }
    30% {
        transform: translateY(-8px);
        opacity: 1;
    }
}

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

.typing-text {
    font-style: italic;
}

/* Message timestamp tooltip */
.message-time {
    cursor: help;
}

/* Header buttons styling */
.chat-header .btn-secondary {
    padding: 0.625rem 1.25rem;
    font-size: 0.9375rem;
    border-radius: 12px;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    font-weight: 500;
}

.chat-header .btn-secondary:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
}

.room-info .btn-secondary {
    margin-left: 0.75rem;
}

@media (max-width: 768px) {
    .messenger-container {
        max-width: 100%;
    }
    
    .chat-container {
        height: 78vh;
        min-height: 550px;
        border-radius: 16px;
    }

    .message {
        max-width: 80%;
        padding: 0.875rem 1.125rem;
    }

    .room-form {
        flex-direction: column;
        gap: 1rem;
    }
    
    .room-form input {
        min-width: 100%;
    }

    .chat-header {
        padding: 1.25rem 1.5rem;
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .room-info {
        justify-content: space-between;
        flex-wrap: wrap;
    }

    .chat-input-container {
        padding: 1.25rem 1.5rem;
        gap: 1rem;
    }

    .send-btn {
        padding: 0.875rem 1.75rem;
        font-size: 1rem;
    }

    .messages-container {
        padding: 1.5rem;
        gap: 0.875rem;
    }
}

@media (max-width: 480px) {
    .messenger-container {
        padding: 0 0.5rem;
    }
    
    .chat-container {
        height: calc(100vh - 8rem);
        min-height: 480px;
        max-height: 750px;
        border-radius: 12px;
    }
    
    .message {
        max-width: 85%;
        padding: 0.75rem 1rem;
    }
    
    .chat-header {
        padding: 1rem 1.25rem;
    }
    
    .chat-input-container {
        padding: 1rem 1.25rem;
    }
    
    .messages-container {
        padding: 1.25rem;
    }
}

/* ==========================================
   UI/UX IMPROVEMENTS
   ========================================== */

/* Date Separators */
.date-separator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 1.5rem 0;
    gap: 1rem;
}

.date-separator::before,
.date-separator::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border-color);
}

.date-separator-text {
    padding: 0.375rem 0.75rem;
    background: var(--bg-secondary);
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 500;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    white-space: nowrap;
}

/* Scroll to Bottom Button */
.scroll-to-bottom-btn {
    position: absolute;
    bottom: 1rem;
    right: 1rem;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--button-bg);
    color: var(--button-text);
    border: none;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    transition: all 0.3s ease;
    z-index: 100;
    font-size: 1.25rem;
}

.scroll-to-bottom-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.2);
}

.scroll-to-bottom-btn.visible {
    display: flex;
}

.scroll-to-bottom-btn .unread-count {
    position: absolute;
    top: -4px;
    right: -4px;
    background: #ef4444;
    color: white;
    border-radius: 10px;
    padding: 0.125rem 0.375rem;
    font-size: 0.625rem;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
}

.messages-container {
    position: relative;
}

/* Message Grouping */
.message-group {
    margin-bottom: 0.75rem;
}

.message-group .message {
    margin-bottom: 0.25rem;
}

.message-group .message:last-child {
    margin-bottom: 0.5rem;
}

.message-group .message:not(:first-child) .message-header {
    display: none;
}

.message-group .message:not(:first-child) {
    margin-left: 1.75rem;
}

/* Better Avatars */
.message-avatar {
    width: 28px !important;
    height: 28px !important;
    font-size: 0.75rem !important;
    font-weight: 600 !important;
    display: inline-flex !important;
    align-items: center !important;
    justify-content: center !important;
    border-radius: 50% !important;
    flex-shrink: 0;
    margin-right: 0.5rem;
    background: linear-gradient(135deg, var(--text-primary) 0%, var(--text-secondary) 100%);
    color: var(--bg-primary);
    border: 2px solid var(--bg-secondary);
}

.message-avatar-own {
    background: linear-gradient(135deg, #4ade80 0%, #22c55e 100%);
    color: white;
}

/* Context Menu */
.message-context-menu {
    position: fixed;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    padding: 0.5rem;
    z-index: 1000;
    min-width: 160px;
    display: none;
    animation: fadeIn 0.2s ease-out;
}

.message-context-menu.visible {
    display: block;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.625rem 0.875rem;
    cursor: pointer;
    border-radius: 6px;
    font-size: 0.875rem;
    color: var(--text-primary);
    transition: all 0.2s ease;
}

.context-menu-item:hover {
    background: var(--bg-primary);
}

.context-menu-item svg {
    width: 16px;
    height: 16px;
    opacity: 0.7;
}

/* Toast Notifications */
.toast-container {
    position: fixed;
    top: 1rem;
    right: 1rem;
    z-index: 10000;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    pointer-events: none;
}

.toast {
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 0.875rem 1.125rem;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 250px;
    max-width: 400px;
    pointer-events: auto;
    animation: slideInRight 0.3s ease-out;
}

@keyframes slideInRight {
    from {
        transform: translateX(100%);
        opacity: 0;
    }
    to {
        transform: translateX(0);
        opacity: 1;
    }
}

.toast-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
}

.toast-message {
    flex: 1;
    font-size: 0.875rem;
    color: var(--text-primary);
}

/* Character Counter */
.char-counter {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-align: right;
    margin-top: 0.25rem;
}

.char-counter.warning {
    color: #f59e0b;
}

.char-counter.error {
    color: #ef4444;
}

/* Skeleton Loaders */
.skeleton-loader {
    background: linear-gradient(90deg, var(--bg-secondary) 25%, var(--bg-primary) 50%, var(--bg-secondary) 75%);
    background-size: 200% 100%;
    animation: skeleton-loading 1.5s ease-in-out infinite;
    border-radius: 8px;
}

@keyframes skeleton-loading {
    0% {
        background-position: 200% 0;
    }
    100% {
        background-position: -200% 0;
    }
}

.skeleton-message {
    height: 60px;
    margin-bottom: 0.75rem;
    border-radius: 14px;
}

/* Better Empty States */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 3rem 1.5rem;
    text-align: center;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 3rem;
    margin-bottom: 1rem;
    opacity: 0.5;
}

.empty-state-title {
    font-size: 1.125rem;
    font-weight: 500;
    color: var(--text-primary);
    margin-bottom: 0.5rem;
}

.empty-state-text {
    font-size: 0.875rem;
    line-height: 1.5;
    max-width: 300px;
}

/* Unread Badges */
.unread-badge {
    background: #ef4444;
    color: white;
    border-radius: 10px;
    padding: 0.125rem 0.5rem;
    font-size: 0.625rem;
    font-weight: 600;
    min-width: 18px;
    text-align: center;
    margin-left: 0.5rem;
}

.room-tab.active .unread-badge {
    background: rgba(255, 255, 255, 0.3);
}

/* Message Copy Indicator */
.message-copy-indicator {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.5rem 0.75rem;
    font-size: 0.75rem;
    color: var(--text-primary);
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    z-index: 100;
    pointer-events: none;
    animation: fadeInOut 1.5s ease-out;
}

@keyframes fadeInOut {
    0%, 100% {
        opacity: 0;
        transform: translate(-50%, -50%) scale(0.9);
    }
    20%, 80% {
        opacity: 1;
        transform: translate(-50%, -50%) scale(1);
    }
}

/* Better Timestamps */
.message-time {
    position: relative;
}

.message-time:hover::after {
    content: attr(data-full-time);
    position: absolute;
    bottom: 100%;
    left: 50%;
    transform: translateX(-50%);
    background: var(--bg-secondary);
    color: var(--text-primary);
    padding: 0.375rem 0.625rem;
    border-radius: 6px;
    font-size: 0.75rem;
    white-space: nowrap;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
    border: 1px solid var(--border-color);
    margin-bottom: 0.5rem;
    z-index: 10;
    pointer-events: none;
}

/* Message Selection */
.message.selected {
    background: var(--bg-secondary) !important;
    border: 2px solid var(--text-primary) !important;
}

.message.own.selected {
    border-color: rgba(250, 249, 246, 0.5) !important;
}

/* Loading Skeleton for Messages */
.messages-loading {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    padding: 1rem;
}

/* Improved Message Spacing */
.message + .date-separator {
    margin-top: 2rem;
}

/* Mobile Improvements */
@media (max-width: 768px) {
    .scroll-to-bottom-btn {
        width: 48px;
        height: 48px;
        bottom: 1.25rem;
        right: 1.25rem;
    }
    
    .message-context-menu {
        min-width: 180px;
        font-size: 0.9375rem;
    }
    
    .context-menu-item {
        padding: 0.75rem 1rem;
    }
    
    .toast {
        min-width: 280px;
        max-width: calc(100vw - 2rem);
    }
}

/* Touch-friendly improvements */
@media (pointer: coarse) {
    .message {
        padding: 0.875rem 1rem;
    }
    
    .context-menu-item {
        min-height: 44px;
    }
}

/* Message Reactions */
.message-reactions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.375rem;
    margin-top: 0.5rem;
    padding-top: 0.5rem;
    border-top: 1px solid var(--border-color);
}

.reaction {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s ease;
}

.reaction:hover {
    background: var(--bg-primary);
    transform: scale(1.05);
}

.reaction.own-reaction {
    background: var(--text-primary);
    color: var(--bg-primary);
    border-color: var(--text-primary);
}

.reaction-emoji {
    font-size: 1rem;
}

.reaction-count {
    font-weight: 500;
    font-size: 0.75rem;
}

.reaction-picker {
    position: absolute;
    bottom: 100%;
    left: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 0.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    display: none;
    flex-wrap: wrap;
    gap: 0.375rem;
    z-index: 100;
    margin-bottom: 0.5rem;
    max-width: 200px;
}

.reaction-picker.visible {
    display: flex;
    animation: fadeIn 0.2s ease-out;
}

.reaction-picker-btn {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg-primary);
    border-radius: 8px;
    font-size: 1.25rem;
    cursor: pointer;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reaction-picker-btn:hover {
    background: var(--border-color);
    transform: scale(1.1);
}

.message-reaction-btn {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 24px;
    height: 24px;
    border: none;
    background: rgba(0, 0, 0, 0.05);
    border-radius: 50%;
    cursor: pointer;
    opacity: 0;
    transition: all 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.875rem;
}

.message:hover .message-reaction-btn {
    opacity: 1;
}

.message.own .message-reaction-btn {
    background: rgba(255, 255, 255, 0.1);
}

/* Message Search */
.message-search {
    position: relative;
    margin-bottom: 1rem;
}

.message-search-input {
    width: 100%;
    padding: 0.75rem 2.5rem 0.75rem 1rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 0.875rem;
}

.message-search-input:focus {
    outline: none;
    border-color: var(--text-primary);
    box-shadow: 0 0 0 3px var(--shadow-color);
}

.message-search-close {
    position: absolute;
    right: 0.75rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1.25rem;
    padding: 0.25rem;
}

.message-search-results {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    max-height: 300px;
    overflow-y: auto;
    margin-top: 0.5rem;
    box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
    z-index: 100;
    display: none;
}

.message-search-results.visible {
    display: block;
}

.search-result-item {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--border-color);
    cursor: pointer;
    transition: background 0.2s ease;
}

.search-result-item:hover {
    background: var(--bg-primary);
}

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

.search-result-text {
    font-size: 0.875rem;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.search-result-meta {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.search-highlight {
    background: #fef08a;
    padding: 0.125rem 0.25rem;
    border-radius: 3px;
}

[data-theme="dark"] .search-highlight {
    background: #854d0e;
    color: #fef08a;
}

/* Keyboard Shortcuts Overlay */
.shortcuts-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    display: none;
    align-items: center;
    justify-content: center;
    z-index: 10000;
    animation: fadeIn 0.2s ease-out;
}

.shortcuts-overlay.visible {
    display: flex;
}

.shortcuts-modal {
    background: var(--bg-primary);
    border-radius: 16px;
    max-width: 500px;
    width: 90%;
    max-height: 80vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    animation: slideUp 0.3s ease-out;
}

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

.shortcuts-header h3 {
    margin: 0;
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--text-primary);
}

.shortcuts-close {
    background: none;
    border: none;
    font-size: 2rem;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 0;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 6px;
    transition: all 0.2s ease;
}

.shortcuts-close:hover {
    background: var(--bg-secondary);
    color: var(--text-primary);
}

.shortcuts-body {
    padding: 1.5rem 2rem;
}

.shortcut-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border-color);
}

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

.shortcut-description {
    font-size: 0.875rem;
    color: var(--text-primary);
}

.shortcut-keys {
    display: flex;
    gap: 0.25rem;
}

.shortcut-key {
    padding: 0.25rem 0.5rem;
    background: var(--bg-secondary);
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.75rem;
    font-family: monospace;
    color: var(--text-primary);
}

/* Link Previews */
.message-link-preview {
    margin-top: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    background: var(--bg-secondary);
}

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

.link-preview-content {
    padding: 0.75rem;
}

.link-preview-title {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 0.25rem;
}

.link-preview-description {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    line-height: 1.4;
}

.link-preview-url {
    font-size: 0.6875rem;
    color: var(--text-secondary);
    font-family: monospace;
    word-break: break-all;
}

/* Better Animations */
@keyframes messageSlideIn {
    from {
        opacity: 0;
        transform: translateY(10px) scale(0.95);
    }
    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.message {
    animation: messageSlideIn 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.message:nth-child(even) {
    animation-delay: 0.05s;
}

.message:nth-child(odd) {
    animation-delay: 0.1s;
}

/* Ripple Effect */
.ripple {
    position: relative;
    overflow: hidden;
}

.ripple::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 0;
    height: 0;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    transform: translate(-50%, -50%);
    transition: width 0.6s, height 0.6s;
}

.ripple:active::after {
    width: 300px;
    height: 300px;
}

/* Mobile Bottom Sheet */
@media (max-width: 768px) {
    .rooms-sidebar {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-height: 60vh;
        border-radius: 18px 18px 0 0;
        transform: translateY(100%);
        transition: transform 0.3s ease-out;
    }
    
    .rooms-sidebar.active {
        transform: translateY(0);
    }
    
    .rooms-sidebar::before {
        content: '';
        position: absolute;
        top: 0.75rem;
        left: 50%;
        transform: translateX(-50%);
        width: 40px;
        height: 4px;
        background: var(--border-color);
        border-radius: 2px;
    }
}

/* Pull to Refresh */
.pull-to-refresh {
    position: absolute;
    top: -60px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-secondary);
    font-size: 0.875rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.pull-to-refresh.visible {
    opacity: 1;
}

.pull-to-refresh-icon {
    animation: spin 1s linear infinite;
}

/* Header overflow menu */
.header-overflow-wrapper {
    position: relative;
    display: contents;
}

.header-overflow-toggle {
    display: none;
}

.header-overflow-menu {
    display: contents;
}

@media (max-width: 768px) {
    .header-overflow-toggle {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        padding: 0.5rem !important;
        min-width: 2.25rem;
    }

    .header-overflow-wrapper {
        display: block;
        position: relative;
    }

    .header-overflow-menu {
        display: none;
        position: absolute;
        top: 100%;
        right: 0;
        z-index: 100;
        background: var(--bg-secondary);
        border: 1px solid var(--border-color);
        border-radius: 10px;
        box-shadow: 0 4px 16px var(--shadow-color);
        padding: 0.5rem;
        min-width: 200px;
        margin-top: 0.5rem;
    }

    .header-overflow-menu.open {
        display: flex;
        flex-direction: column;
        gap: 0.25rem;
    }

    .header-overflow-menu .btn-secondary {
        width: 100%;
        text-align: left;
        justify-content: flex-start;
        margin-left: 0 !important;
        border-radius: 8px;
        padding: 0.625rem 0.875rem !important;
    }
}

