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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    background: #17212b;
    height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Auth */
.auth-container {
    background: #ffffff;
    padding: 30px;
    border-radius: 12px;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    width: 400px;
}

.auth-container h2 {
    text-align: center;
    margin-bottom: 24px;
    color: #17212b;
}

.auth-input {
    width: 100%;
    padding: 12px;
    margin: 8px 0;
    border: 1px solid #e0e0e0;
    border-radius: 8px;
    font-size: 14px;
}

.auth-buttons {
    display: flex;
    gap: 10px;
    margin-top: 16px;
}

.auth-buttons button {
    flex: 1;
    padding: 10px;
    border: none;
    border-radius: 8px;
    background: #0088cc;
    color: white;
    font-weight: bold;
    cursor: pointer;
}

.auth-buttons button:hover {
    background: #006699;
}

.error {
    color: #e53935;
    font-size: 12px;
    margin-top: 10px;
    text-align: center;
}

/* Main chat */
.chat-container {
    display: flex;
    width: 90vw;
    height: 90vh;
    background: #ffffff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}

/* Sidebar */
.sidebar {
    width: 300px;
    background: #f5f5f5;
    border-right: 1px solid #e0e0e0;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
}

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

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

#currentUsername {
    font-weight: bold;
    background: #e0e0e0;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
}

.logout-btn {
    background: #e53935;
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 16px;
}

.tabs {
    display: flex;
    border-bottom: 1px solid #e0e0e0;
}

.tab-btn {
    flex: 1;
    background: none;
    border: none;
    padding: 12px;
    cursor: pointer;
    font-weight: 500;
    color: #656565;
}

.tab-btn.active {
    color: #0088cc;
    border-bottom: 2px solid #0088cc;
}

.tab-content {
    display: none;
    flex-direction: column;
    gap: 8px;
    padding: 12px;
    overflow-y: auto;
}

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

.contacts-list, .chats-list, .requests-list, .search-results {
    max-height: 400px;
    overflow-y: auto;
}

.contact-item, .chat-item, .request-item, .search-result-item {
    background: white;
    padding: 12px;
    margin: 4px 0;
    border-radius: 8px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
    transition: background 0.2s;
}

.contact-item:hover, .chat-item:hover, .search-result-item:hover {
    background: #f0f0f0;
}

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

.chat-btn, .remove-contact-btn, .accept-request, .reject-request, .add-contact-btn, .send-friend-request-btn {
    background: #0088cc;
    border: none;
    color: white;
    border-radius: 6px;
    padding: 4px 8px;
    cursor: pointer;
    font-size: 12px;
}

.remove-contact-btn, .reject-request {
    background: #e53935;
}

.create-group-btn, .add-contact-btn {
    background: #0088cc;
    border: none;
    color: white;
    padding: 10px;
    border-radius: 8px;
    cursor: pointer;
    margin-top: 12px;
    font-weight: bold;
}

/* Main chat area */
.main {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #ffffff;
}

.chat-header {
    padding: 16px;
    background: #f5f5f5;
    border-bottom: 1px solid #e0e0e0;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-actions {
    display: flex;
    gap: 8px;
    align-items: center;
}

.call-btn, .voice-btn, .search-messages-btn {
    background: #0088cc;
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    cursor: pointer;
}

.voice-btn {
    background: #9b59b6;
}

.search-messages-input {
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid #e0e0e0;
    width: 150px;
}

.typing-indicator {
    font-size: 12px;
    color: #888;
    font-style: italic;
}

.messages {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    background: #f5f5f5;
    display: flex;
    flex-direction: column;
}

.message {
    background: white;
    padding: 8px 12px;
    margin-bottom: 8px;
    border-radius: 18px;
    max-width: 70%;
    align-self: flex-start;
    box-shadow: 0 1px 1px rgba(0,0,0,0.05);
    word-wrap: break-word;
}

.message.own-message {
    align-self: flex-end;
    background: #dcf8c5;
}

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

.message-time {
    font-size: 10px;
    color: #888;
    text-align: right;
}

.edited-badge {
    font-size: 10px;
    color: #888;
    margin-left: 6px;
}

.message-image {
    max-width: 200px;
    max-height: 200px;
    border-radius: 10px;
    margin-top: 5px;
    cursor: pointer;
}

.input-area {
    display: flex;
    padding: 12px;
    background: #f5f5f5;
    gap: 8px;
    border-top: 1px solid #e0e0e0;
}

#messageInput {
    flex: 1;
    padding: 10px;
    border: 1px solid #e0e0e0;
    border-radius: 24px;
    font-size: 14px;
}

#fileBtn, #sendBtn {
    background: #0088cc;
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 24px;
    cursor: pointer;
}

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

.custom-modal-content {
    background: white;
    padding: 20px;
    border-radius: 12px;
    width: 300px;
    text-align: center;
}

.modal-message {
    font-size: 16px;
    margin-bottom: 20px;
    display: block;
}

.modal-input {
    width: 100%;
    padding: 8px;
    margin: 15px 0;
    border: 1px solid #ccc;
    border-radius: 8px;
}

.modal-buttons {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-ok-btn, .modal-cancel-btn {
    padding: 6px 20px;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    font-weight: bold;
}

.modal-ok-btn {
    background: #0088cc;
    color: white;
}

.modal-cancel-btn {
    background: #e53935;
    color: white;
}

.image-modal-content {
    max-width: 90%;
    max-height: 90%;
    border-radius: 12px;
}

.image-modal-close {
    position: absolute;
    top: 20px;
    right: 35px;
    color: white;
    font-size: 40px;
    font-weight: bold;
    cursor: pointer;
    background: rgba(0,0,0,0.5);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* Responsive */
@media (max-width: 768px) {
    .chat-container {
        flex-direction: column;
        width: 100vw;
        height: 100vh;
        border-radius: 0;
    }
    .sidebar {
        width: 100%;
        height: 40%;
        flex-direction: row;
        flex-wrap: wrap;
    }
    .main {
        height: 60%;
    }
    .tabs {
        width: 100%;
    }
    .message {
        max-width: 90%;
    }
    .chat-actions .search-messages-input {
        width: 100px;
    }
}
