* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #6366f1;
    --primary-dark: #4f46e5;
    --primary-light: #818cf8;
    --bg-dark: #1f2937;
    --bg-darker: #111827;
    --bg-light: #f3f4f6;
    --bg-white: #ffffff;
    --text-primary: #111827;
    --text-secondary: #6b7280;
    --text-light: #9ca3af;
    --border: #e5e7eb;
    --success: #10b981;
    --warning: #f59e0b;
    --danger: #ef4444;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-darker);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.app-container {
    display: flex;
    height: 100vh;
    max-width: 1600px;
    margin: 0 auto;
    background: var(--bg-white);
    box-shadow: var(--shadow-lg);
}

/* Sidebar */
.sidebar {
    width: 360px;
    background: var(--bg-white);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

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

.logo {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
}

.logo i {
    font-size: 1.5rem;
}

.new-chat-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.new-chat-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

.search-box {
    padding: 12px 16px;
    position: relative;
}

.search-box i {
    position: absolute;
    left: 28px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 0.875rem;
}

.search-box input {
    width: 100%;
    padding: 10px 12px 10px 36px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 0.875rem;
    outline: none;
    transition: all 0.2s;
    background: var(--bg-light);
}

.search-box input:focus {
    border-color: var(--primary);
    background: var(--bg-white);
}

.chat-list {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.chat-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
    margin-bottom: 4px;
}

.chat-item:hover {
    background: var(--bg-light);
}

.chat-item.active {
    background: var(--primary);
    color: white;
}

.chat-item.active .chat-meta,
.chat-item.active .chat-preview,
.chat-item.active .chat-time {
    color: rgba(255, 255, 255, 0.8);
}

.chat-item img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    object-fit: cover;
}

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

.chat-header-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

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

.chat-meta {
    display: flex;
    align-items: center;
    gap: 6px;
}

.chat-time {
    font-size: 0.75rem;
    color: var(--text-light);
}

.unread-badge {
    background: var(--primary);
    color: white;
    font-size: 0.6875rem;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.chat-preview {
    font-size: 0.875rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
}

.user-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.user-profile .avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
}

.user-info {
    display: flex;
    flex-direction: column;
}

.user-name {
    font-weight: 600;
    font-size: 0.9375rem;
}

.user-status {
    font-size: 0.75rem;
    color: var(--success);
    display: flex;
    align-items: center;
    gap: 4px;
}

.user-status::before {
    content: '';
    width: 6px;
    height: 6px;
    background: var(--success);
    border-radius: 50%;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-light);
}

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

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
}

.chat-header-info .avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
}

.chat-header-text h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 2px;
}

.chat-header-text span {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

.chat-header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: var(--bg-light);
    color: var(--text-primary);
}

/* Messages */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
}

.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: var(--text-light);
    text-align: center;
    padding: 40px;
}

.empty-state i {
    font-size: 4rem;
    margin-bottom: 20px;
    color: var(--primary-light);
}

.empty-state h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.empty-state p {
    font-size: 0.9375rem;
    max-width: 300px;
}

.messages-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.message {
    max-width: 70%;
    padding: 12px 16px;
    border-radius: 18px;
    position: relative;
    animation: messageSlide 0.3s ease;
}

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

.message.sent {
    align-self: flex-end;
    background: var(--primary);
    color: white;
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: var(--bg-white);
    color: var(--text-primary);
    border-bottom-left-radius: 4px;
    box-shadow: var(--shadow-sm);
}

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

.message-time {
    font-size: 0.6875rem;
    opacity: 0.7;
    margin-top: 4px;
    text-align: right;
}

.message-image {
    max-width: 100%;
    border-radius: 12px;
    cursor: pointer;
    transition: transform 0.2s;
}

.message-image:hover {
    transform: scale(1.02);
}

.message-video {
    max-width: 100%;
    border-radius: 12px;
}

.message-audio {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 8px;
}

.audio-play-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.2);
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.message.received .audio-play-btn {
    background: var(--primary);
    color: white;
}

.audio-waveform {
    flex: 1;
    height: 30px;
    display: flex;
    align-items: center;
    gap: 3px;
}

.wave-bar {
    width: 3px;
    background: currentColor;
    border-radius: 2px;
    opacity: 0.6;
    animation: wave 1s ease-in-out infinite;
}

@keyframes wave {
    0%, 100% { height: 20%; }
    50% { height: 100%; }
}

.audio-duration {
    font-size: 0.75rem;
    opacity: 0.8;
}

/* Input Area */
.input-area {
    padding: 16px 24px;
    background: var(--bg-white);
    border-top: 1px solid var(--border);
}

.input-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 12px;
}

.toolbar-btn {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.toolbar-btn:hover {
    background: var(--bg-light);
    color: var(--primary);
}

.toolbar-btn.recording {
    background: var(--danger);
    color: white;
    animation: pulse 1s infinite;
}

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

.message-input-wrapper {
    display: flex;
    gap: 12px;
    align-items: center;
}

.message-input-wrapper input {
    flex: 1;
    padding: 12px 20px;
    border: 1px solid var(--border);
    border-radius: 24px;
    font-size: 0.9375rem;
    outline: none;
    transition: all 0.2s;
}

.message-input-wrapper input:focus {
    border-color: var(--primary);
}

.send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    background: var(--primary);
    color: white;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

/* Recording Indicator */
.recording-indicator {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--danger);
    color: white;
    padding: 12px 24px;
    border-radius: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.recording-pulse {
    width: 12px;
    height: 12px;
    background: white;
    border-radius: 50%;
    animation: recordingPulse 1s infinite;
}

@keyframes recordingPulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.5; transform: scale(1.2); }
}

.cancel-recording {
    background: rgba(255, 255, 255, 0.2);
    border: none;
    color: white;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.cancel-recording:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Modals */
.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--bg-white);
    border-radius: 16px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow: hidden;
    animation: modalSlide 0.3s ease;
}

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

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

.modal-header h3 {
    font-size: 1.125rem;
    font-weight: 600;
}

.close-btn {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

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

.modal-body {
    padding: 16px;
    max-height: 60vh;
    overflow-y: auto;
}

.friends-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.friend-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    transition: all 0.2s;
}

.friend-item:hover {
    background: var(--bg-light);
}

.friend-item img {
    width: 48px;
    height: 48px;
    border-radius: 50%;
}

.friend-info {
    flex: 1;
}

.friend-name {
    font-weight: 600;
    font-size: 0.9375rem;
}

.friend-status {
    font-size: 0.8125rem;
    color: var(--text-secondary);
}

/* Image/Video Modals */
.image-modal,
.video-modal {
    background: rgba(0, 0, 0, 0.9);
}

.image-modal-content,
.video-modal-content {
    max-width: 90vw;
    max-height: 90vh;
    background: transparent;
    display: flex;
    align-items: center;
    justify-content: center;
}

.image-modal-content img,
.video-modal-content video {
    max-width: 100%;
    max-height: 85vh;
    border-radius: 8px;
}

.image-modal-content .close-btn,
.video-modal-content .close-btn {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(0, 0, 0, 0.5);
    color: white;
    width: 40px;
    height: 40px;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--text-light);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: fixed;
        left: -100%;
        top: 0;
        height: 100vh;
        z-index: 100;
        transition: left 0.3s ease;
    }
    
    .sidebar.open {
        left: 0;
    }
    
    .chat-area {
        width: 100%;
    }
    
    .message {
        max-width: 85%;
    }
}