/* Base styles */
body, html {
    margin: 0;
    padding: 0;
    height: 100%;
    width: 100%;
    overflow: hidden;
    font-family: 'Inter', system-ui, -apple-system, sans-serif;
    -webkit-tap-highlight-color: transparent;
}

/* Chat messages */
.message-sent, .message-received {
    padding: 8px 16px;
    margin: 1px 8px;
    border-radius: 20px;
    font-size: 15px;
    width: fit-content;
    max-width: 85%;
    line-height: 1.4;
}

.message-sent {
    background: #7646FF;
    color: white;
    margin-left: auto;
    margin-right: 8px;
}

.message-received {
    background: #F1F1F1;
    color: black;
    margin-right: auto;
    margin-left: 8px;
}

/* Hide timestamp */
.message-timestamp {
    display: none;
}

/* Message container */
.message-container {
    display: flex;
    flex-direction: column;
    gap: 1px;
    width: 100%;
    padding: 8px;
}

/* Message groups */
.message-group {
    margin-bottom: 4px;
    display: flex;
    flex-direction: column;
}

.message-group .message-sent,
.message-group .message-received {
    margin-bottom: 4px;
}

.message-group .message-sent:last-child,
.message-group .message-received:last-child {
    margin-bottom: 4px;
}

/* Chat sidebar */
.chat-sidebar {
    transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    will-change: transform;
}

.chat-sidebar.active {
    transform: translateX(0) !important;
}

/* Contact items */
.contact-item {
    transition: all 0.2s ease;
    border-radius: 0.75rem;
}

.contact-item:active {
    background-color: #f3f4f6;
}

.contact-item:hover {
    transform: translateX(4px);
}

/* Mobile styles */
@media screen and (max-width: 480px) {
    .message-sent, .message-received {
        padding: 6px 12px;
        font-size: 13px;
        max-width: 75%;
        line-height: 1.3;
    }

    .message-sent {
        margin-right: 4px;
    }

    .message-received {
        margin-left: 4px;
    }
    
    .message-container {
        padding: 4px;
    }
}

/* Mobile menu styles */
@media (max-width: 768px) {
    .chat-sidebar {
        height: 100vh;
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        z-index: 50;
        background-color: #fff;
    }

    #sidebar-backdrop {
        position: fixed;
        inset: 0;
        background-color: rgba(0, 0, 0, 0.5);
        backdrop-filter: blur(1px);
        z-index: 40;
        opacity: 1;
        transition: opacity 0.2s ease-in-out;
    }

    #sidebar-backdrop.hidden {
        opacity: 0;
        pointer-events: none;
    }

    .chat-sidebar.-translate-x-full + #sidebar-backdrop {
        opacity: 0;
        pointer-events: none;
    }

    #contact-list {
        height: calc(100vh - 200px);
        overflow-y: auto;
    }
}

/* Hide main chat on mobile when menu is open */
@media (max-width: 768px) {
    .chat-sidebar:not(.-translate-x-full) ~ .flex-1 {
        display: none;
    }
}

/* Loading spinner */
.loading-spinner {
    border: 3px solid #f3f3f3;
    border-radius: 50%;
    border-top: 3px solid #3498db;
    width: 24px;
    height: 24px;
    animation: spin 1s linear infinite;
}

/* Chat area */
#chat-messages {
    scroll-behavior: smooth;
    scrollbar-width: thin;
    scrollbar-color: rgba(0,0,0,0.2) transparent;
}

#chat-messages::-webkit-scrollbar {
    width: 6px;
}

#chat-messages::-webkit-scrollbar-track {
    background: transparent;
}

#chat-messages::-webkit-scrollbar-thumb {
    background-color: rgba(0,0,0,0.2);
    border-radius: 3px;
}

/* Message input */
.message-input-container {
    background-color: white;
    border-radius: 1rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

#message-input {
    min-height: 24px;
    max-height: 120px;
    resize: none;
}

/* Active user indicator */
#active-user {
    position: relative;
}

#active-user::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    background: inherit;
    border-radius: inherit;
    animation: pulse 2s infinite;
    opacity: 0.5;
}

/* Notifications */
#new-message-popup {
    animation: slideIn 0.3s ease-out;
    box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}

/* Backdrop */
#sidebar-backdrop {
    backdrop-filter: blur(2px);
    transition: opacity 0.3s ease;
}

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

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

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

@keyframes pulse {
    0% { 
        transform: scale(1);
        opacity: 0.5;
    }
    50% { 
        transform: scale(1.5);
        opacity: 0;
    }
    100% { 
        transform: scale(1);
        opacity: 0.5;
    }
}

/* Touch device optimizations */
@media (hover: none) {
    .contact-item:hover {
        transform: none;
    }

    .contact-item:active {
        background-color: #f3f4f6;
        transform: scale(0.98);
    }
}

/* Safe area handling */
@supports(padding: max(0px)) {
    .message-input-container {
        padding-bottom: max(1rem, env(safe-area-inset-bottom));
    }
}