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

:root {
    --primary-color: #25D366;
    --secondary-color: #128C7E;
    --bg-color: #111B21;
    --sidebar-bg: #202C33;
    --chat-bg: #0B141A;
    --message-bg: #005C4B;
    --incoming-message-bg: #202C33;
    --border-color: #2A3942;
    --text-primary: #E9EDEF;
    --text-secondary: #8696A0;
    --hover-bg: #2A3942;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
}

.hidden {
    display: none !important;
}

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, var(--secondary-color), var(--primary-color));
}

.login-container {
    width: 100%;
    max-width: 400px;
    padding: 20px;
}

.login-box {
    background: var(--sidebar-bg);
    border-radius: 10px;
    padding: 40px;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.3);
}

.logo {
    text-align: center;
    margin-bottom: 30px;
}

.logo h1 {
    margin-top: 15px;
    font-size: 24px;
    color: var(--text-primary);
}

.tabs {
    display: flex;
    gap: 10px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

.tab {
    flex: 1;
    padding: 12px;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 14px;
    transition: all 0.3s;
    border-bottom: 2px solid transparent;
}

.tab.active {
    color: var(--primary-color);
    border-bottom-color: var(--primary-color);
}

.tab-content {
    display: none;
}

.tab-content.active {
    display: block;
}

.input-group {
    margin-bottom: 20px;
}

.input-group input {
    width: 100%;
    padding: 12px 15px;
    background: var(--chat-bg);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    color: var(--text-primary);
    font-size: 14px;
}

.input-group input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.btn-primary {
    width: 100%;
    padding: 12px;
    background: var(--primary-color);
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.3s;
}

.btn-primary:hover {
    background: var(--secondary-color);
}

.error-message {
    margin-top: 15px;
    padding: 10px;
    background: #ff4444;
    color: white;
    border-radius: 5px;
    font-size: 14px;
    text-align: center;
    display: none;
}

.error-message.show {
    display: block;
}

/* Main App */
.app-container {
    display: flex;
    height: 100vh;
}

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

.sidebar-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    background: var(--bg-color);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 10px;
}

.avatar {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    object-fit: cover;
}

.avatar-large {
    width: 80px;
    height: 80px;
    border-radius: 50%;
    object-fit: cover;
}

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

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 50%;
    transition: background 0.3s;
}

.icon-btn:hover {
    background: var(--hover-bg);
}

.search-box {
    padding: 10px 15px;
    background: var(--bg-color);
}

.search-box input {
    width: 100%;
    padding: 10px 15px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.chat-list, .call-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item, .call-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    cursor: pointer;
    border-bottom: 1px solid var(--border-color);
    transition: background 0.2s;
}

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

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

.chat-item-content {
    flex: 1;
    margin-left: 12px;
    overflow: hidden;
}

.chat-item-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.chat-item-name {
    font-weight: 500;
    color: var(--text-primary);
}

.chat-item-time {
    font-size: 12px;
    color: var(--text-secondary);
}

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

.online-indicator {
    width: 10px;
    height: 10px;
    background: var(--primary-color);
    border-radius: 50%;
    display: inline-block;
    margin-right: 5px;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    position: relative;
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--chat-bg);
    text-align: center;
    padding: 40px;
}

.welcome-screen h2 {
    margin: 20px 0 10px;
}

.welcome-screen p {
    color: var(--text-secondary);
}

.chat-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--chat-bg);
}

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

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

.chat-status {
    font-size: 12px;
    color: var(--text-secondary);
}

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

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100" viewBox="0 0 100 100"><text x="50%" y="50%" text-anchor="middle" fill="%23ffffff" fill-opacity="0.03" font-size="70">💬</text></svg>');
}

.message {
    display: flex;
    margin-bottom: 12px;
    animation: messageSlide 0.3s ease;
}

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

.message.outgoing {
    justify-content: flex-end;
}

.message-bubble {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 8px;
    position: relative;
    word-wrap: break-word;
}

.message.incoming .message-bubble {
    background: var(--incoming-message-bg);
}

.message.outgoing .message-bubble {
    background: var(--message-bg);
}

.message-content {
    margin-bottom: 4px;
}

.message-media {
    max-width: 100%;
    border-radius: 8px;
    margin-bottom: 4px;
}

.forwarded-label {
    font-size: 11px;
    color: var(--text-secondary);
    font-style: italic;
    margin-bottom: 4px;
}

.message-time {
    font-size: 11px;
    color: var(--text-secondary);
    text-align: right;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 10px 12px;
    background: var(--incoming-message-bg);
    border-radius: 18px;
    width: fit-content;
    margin-bottom: 12px;
}

.typing-indicator span {
    width: 8px;
    height: 8px;
    background: var(--text-secondary);
    border-radius: 50%;
    animation: typing 1.4s infinite;
}

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

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

@keyframes typing {
    0%, 60%, 100% {
        opacity: 0.3;
        transform: translateY(0);
    }
    30% {
        opacity: 1;
        transform: translateY(-10px);
    }
}

.message-input-container {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 20px;
    background: var(--bg-color);
    border-top: 1px solid var(--border-color);
}

#messageInput {
    flex: 1;
    padding: 12px 15px;
    background: var(--sidebar-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

#messageInput:focus {
    outline: none;
    border-color: var(--primary-color);
}

#sendBtn {
    background: var(--primary-color);
    color: white;
    padding: 10px 15px;
    border-radius: 50%;
}

/* Video Call */
.video-call-container {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: var(--chat-bg);
    z-index: 100;
    display: flex;
    flex-direction: column;
}

.video-header {
    padding: 20px;
    text-align: center;
    background: rgba(0, 0, 0, 0.5);
}

.video-grid {
    flex: 1;
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    padding: 10px;
    position: relative;
}

#remoteVideo {
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

#localVideo {
    position: absolute;
    bottom: 20px;
    right: 20px;
    width: 200px;
    height: 150px;
    object-fit: cover;
    border-radius: 8px;
    border: 2px solid var(--primary-color);
}

.call-controls {
    display: flex;
    justify-content: center;
    gap: 20px;
    padding: 20px;
    background: rgba(0, 0, 0, 0.5);
}

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

.call-btn:hover {
    transform: scale(1.1);
}

.call-btn.end-call {
    background: #ff4444;
}

.call-btn.accept {
    background: var(--primary-color);
    width: 60px;
    height: 60px;
}

.call-btn.reject {
    background: #ff4444;
    width: 60px;
    height: 60px;
}

/* Incoming Call Notification */
.incoming-call-notification {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 1000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.incoming-call-content {
    text-align: center;
    padding: 40px;
}

#incomingCallerName {
    font-size: 24px;
    margin: 20px 0 10px;
}

#incomingCallType {
    color: var(--text-secondary);
    margin-bottom: 40px;
}

.incoming-call-actions {
    display: flex;
    gap: 40px;
    justify-content: center;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.7);
    z-index: 999;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-content {
    background: var(--sidebar-bg);
    border-radius: 10px;
    width: 90%;
    max-width: 500px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

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

.close-btn {
    background: none;
    border: none;
    font-size: 28px;
    color: var(--text-secondary);
    cursor: pointer;
}

.modal-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

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

::-webkit-scrollbar-track {
    background: var(--chat-bg);
}

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

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

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

    .sidebar.hidden-mobile {
        display: none;
    }

    #localVideo {
        width: 100px;
        height: 75px;
    }
}

/* ============================================
   ATTACHMENT MENU (WhatsApp Style)
   ============================================ */

.attachment-menu {
    position: absolute;
    bottom: 70px;
    left: 20px;
    background: var(--sidebar-bg);
    border-radius: 10px;
    padding: 15px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 15px;
    z-index: 100;
    animation: slideUp 0.3s ease;
}

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

.attachment-option {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    padding: 10px;
    border-radius: 8px;
    transition: background 0.2s;
}

.attachment-option:hover {
    background: var(--hover-bg);
}

.attachment-icon {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.2s;
}

.attachment-option:hover .attachment-icon {
    transform: scale(1.1);
}

.attachment-option span {
    font-size: 13px;
    color: var(--text-primary);
}

/* ============================================
   FILE PREVIEW MODAL
   ============================================ */

.file-preview-content {
    max-width: 600px;
}

#filePreviewContainer {
    min-height: 200px;
    max-height: 400px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 15px;
}

.file-preview-item {
    background: var(--chat-bg);
    padding: 15px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 12px;
}

.file-preview-item img,
.file-preview-item video {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
}

.file-preview-icon {
    width: 50px;
    height: 50px;
    background: var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.file-preview-info {
    flex: 1;
}

.file-preview-name {
    font-weight: 500;
    margin-bottom: 4px;
    word-break: break-all;
}

.file-preview-size {
    font-size: 12px;
    color: var(--text-secondary);
}

.caption-input {
    width: 100%;
    padding: 12px;
    background: var(--chat-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    color: var(--text-primary);
    font-size: 14px;
}

.caption-input:focus {
    outline: none;
    border-color: var(--primary-color);
}

.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 15px 20px;
    border-top: 1px solid var(--border-color);
}

.btn-secondary {
    padding: 10px 20px;
    background: var(--hover-bg);
    color: var(--text-primary);
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
}

.btn-secondary:hover {
    background: var(--border-color);
}

/* ============================================
   MESSAGE BUBBLES WITH FILES
   ============================================ */

.message-file {
    max-width: 100%;
    margin-bottom: 5px;
}

.message-file img {
    max-width: 300px;
    max-height: 300px;
    border-radius: 8px;
    cursor: pointer;
    transition: opacity 0.2s;
}

.message-file img:hover {
    opacity: 0.9;
}

.message-file video {
    max-width: 300px;
    border-radius: 8px;
}

.message-file audio {
    width: 100%;
    max-width: 300px;
}

.message-document {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px;
    background: rgba(0, 0, 0, 0.1);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.2s;
    max-width: 300px;
}

.message-document:hover {
    background: rgba(0, 0, 0, 0.15);
}

.document-icon {
    width: 40px;
    height: 40px;
    background: var(--primary-color);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.document-name {
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.document-size {
    font-size: 12px;
    color: var(--text-secondary);
}

.download-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
}

/* PDF Icon */
.pdf-icon { background: #F40F02; }
.doc-icon { background: #2B579A; }
.xls-icon { background: #217346; }
.zip-icon { background: #FFA500; }
.txt-icon { background: #666; }

/* ============================================
   EMOJI PICKER
   ============================================ */

.emoji-picker {
    position: absolute;
    bottom: 70px;
    right: 80px;
    width: 320px;
    height: 350px;
    background: var(--sidebar-bg);
    border-radius: 10px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
    z-index: 100;
    overflow: hidden;
}

.emoji-grid {
    padding: 10px;
    height: 100%;
    overflow-y: auto;
    display: grid;
    grid-template-columns: repeat(8, 1fr);
    gap: 5px;
}

.emoji-item {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border-radius: 4px;
    font-size: 24px;
    transition: background 0.2s;
}

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

/* Send button highlight when text is entered */
.send-btn.active {
    background: var(--primary-color);
    color: white;
}

/* File upload progress */
.upload-progress {
    width: 100%;
    height: 4px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 5px;
}

.upload-progress-bar {
    height: 100%;
    background: var(--primary-color);
    transition: width 0.3s;
}

/* Loading indicator for file uploads */
.message-loading {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
}

.loading-spinner {
    width: 20px;
    height: 20px;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Image lightbox */
.image-lightbox {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.9);
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: zoom-out;
}

.image-lightbox img {
    max-width: 90%;
    max-height: 90%;
    border-radius: 8px;
}

.lightbox-close {
    position: absolute;
    top: 20px;
    right: 20px;
    background: rgba(255, 255, 255, 0.1);
    border: none;
    color: white;
    font-size: 32px;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lightbox-close:hover {
    background: rgba(255, 255, 255, 0.2);
}