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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: #1a1a2e;
    color: #e0e0e0;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}

#app {
    display: flex;
    height: 100vh;
    height: 100dvh;
}

#sidebar {
    width: 300px;
    min-width: 300px;
    background: #16213e;
    border-right: 1px solid #0f3460;
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 15px;
    border-bottom: 1px solid #0f3460;
    display: flex;
    align-items: center;
    gap: 10px;
    flex-wrap: wrap;
}

.sidebar-header h2 {
    color: #e94560;
    display: none;
}

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

.avatar-circle {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #e94560;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
    cursor: pointer;
}

.avatar-circle img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.contact-avatar {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background: #0f3460;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.contact-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.profile-avatar-large {
    width: 150px;
    height: 150px;
    border-radius: 50%;
    background: #e94560;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 60px;
    font-weight: bold;
    color: white;
    margin: 0 auto 10px;
    overflow: hidden;
}

.profile-avatar-large img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.partner-avatar-full {
    width: 100%;
    max-height: 300px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 10px;
    overflow: hidden;
    border-radius: 12px;
}

.partner-avatar-full img {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: 12px;
}

.partner-avatar-full .avatar-placeholder {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: #e94560;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 50px;
    font-weight: bold;
    color: white;
}

.profile-avatar-label {
    display: block;
    text-align: center;
    color: #e94560;
    font-size: 12px;
    cursor: pointer;
    margin-bottom: 5px;
}

.profile-avatar-label:hover {
    color: #c73a52;
}

.profile-remove-avatar {
    display: block;
    margin: 0 auto 15px;
    background: none;
    border: none;
    color: #888;
    font-size: 11px;
    cursor: pointer;
}

.profile-remove-avatar:hover {
    color: #ff6b6b;
}

.uid-display {
    font-size: 11px;
    color: #888;
    word-break: break-all;
    padding: 5px;
    background: #0f3460;
    border-radius: 4px;
    cursor: pointer;
}

.uid-display:hover {
    background: #1a4a7a;
}

#user-search {
    padding: 10px;
    position: relative;
}

#search-input {
    width: 100%;
    padding: 8px;
    border: 1px solid #0f3460;
    border-radius: 4px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 12px;
}

#search-results {
    display: none;
    position: absolute;
    top: 100%;
    left: 10px;
    right: 10px;
    background: #16213e;
    border: 1px solid #0f3460;
    border-radius: 4px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
}

.search-result-item {
    padding: 10px 12px;
    cursor: pointer;
    font-size: 13px;
    color: #e0e0e0;
    border-bottom: 1px solid #0f3460;
}

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

.search-result-item:hover {
    background: #0f3460;
}

#add-user-btn {
    padding: 8px 12px;
    background: #e94560;
    border: none;
    border-radius: 4px;
    color: white;
    cursor: pointer;
    font-size: 16px;
}

#contacts-list {
    flex: 1;
    overflow-y: auto;
}

.contact-item {
    padding: 12px 15px;
    border-bottom: 1px solid #0f3460;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
}

.contact-item:hover {
    background: #0f3460;
}

.contact-item.active {
    background: #e94560;
}

.contact-info {
    flex: 1;
    overflow: hidden;
}

.contact-uid {
    font-size: 13px;
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 2px;
}

.contact-last-msg {
    font-size: 11px;
    color: #888;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.contact-status {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: #555;
}

.contact-status.online {
    background: #4caf50;
}

#chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    min-width: 0;
}

#chat-header {
    padding: 15px 20px;
    background: #16213e;
    border-bottom: 1px solid #0f3460;
    display: flex;
    align-items: center;
    gap: 10px;
}

#back-btn {
    display: none;
    background: none;
    border: none;
    color: #e94560;
    font-size: 20px;
    cursor: pointer;
    padding: 5px;
}

#chat-with {
    font-weight: bold;
    flex: 1;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#chat-status {
    font-size: 12px;
    color: #888;
}

#messages {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
}

.message {
    max-width: 70%;
    padding: 10px 15px;
    border-radius: 18px;
    position: relative;
    word-wrap: break-word;
}

.message.sent {
    align-self: flex-end;
    background: #e94560;
    color: white;
}

.message.received {
    align-self: flex-start;
    background: #0f3460;
}

.message-time {
    font-size: 10px;
    opacity: 0.7;
}

.message-meta {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-top: 4px;
    justify-content: flex-end;
}

.message-status {
    font-size: 10px;
    opacity: 0.7;
}

.delete-btn {
    background: none;
    border: none;
    color: inherit;
    opacity: 0;
    cursor: pointer;
    font-size: 12px;
    padding: 0 2px;
    transition: opacity 0.2s;
}

.message:hover .delete-btn {
    opacity: 0.6;
}

.delete-btn:hover {
    opacity: 1 !important;
    color: #ff6b6b;
}

#input-area {
    padding: 15px 20px;
    background: #16213e;
    border-top: 1px solid #0f3460;
    display: flex;
    gap: 10px;
}

#message-input {
    flex: 1;
    padding: 12px;
    border: 1px solid #0f3460;
    border-radius: 20px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 16px;
}

#message-input:disabled {
    opacity: 0.5;
}

#send-btn {
    padding: 12px 24px;
    background: #e94560;
    border: none;
    border-radius: 20px;
    color: white;
    cursor: pointer;
    font-weight: bold;
}

#send-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#send-btn:hover:not(:disabled) {
    background: #c73a52;
}

.auth-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-radius: 8px;
    overflow: hidden;
    border: 1px solid #0f3460;
}

.auth-tab {
    flex: 1;
    padding: 10px;
    text-align: center;
    cursor: pointer;
    font-size: 14px;
    color: #888;
    background: #1a1a2e;
    transition: all 0.2s;
}

.auth-tab.active {
    background: #e94560;
    color: white;
}

.auth-tab:hover:not(.active) {
    background: #0f3460;
}

#auth-login-form input,
#auth-register-form input {
    width: 100%;
    padding: 12px;
    border: 1px solid #0f3460;
    border-radius: 8px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 14px;
    margin-bottom: 12px;
    text-align: left;
}

.auth-btn {
    width: 100%;
    padding: 12px;
    background: #e94560;
    border: none;
    border-radius: 8px;
    color: white;
    font-size: 14px;
    font-weight: bold;
    cursor: pointer;
}

.auth-btn:hover {
    background: #c73a52;
}

.logout-btn {
    margin-top: 8px;
    padding: 5px 12px;
    background: transparent;
    border: 1px solid #555;
    border-radius: 4px;
    color: #888;
    font-size: 11px;
    cursor: pointer;
    width: 100%;
}

.logout-btn:hover {
    border-color: #e94560;
    color: #e94560;
}

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

.modal-content {
    background: #16213e;
    padding: 30px;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    text-align: center;
}

.modal-content h3 {
    color: #e94560;
    margin-bottom: 15px;
}

.modal-content p {
    font-size: 14px;
    color: #888;
    margin-bottom: 20px;
}

.modal-content input {
    width: 100%;
    padding: 12px;
    border: 1px solid #0f3460;
    border-radius: 8px;
    background: #1a1a2e;
    color: #e0e0e0;
    font-size: 16px;
    margin-bottom: 20px;
    text-align: center;
}

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

.modal-buttons button {
    padding: 12px 24px;
    border: none;
    border-radius: 8px;
    font-size: 14px;
    cursor: pointer;
    font-weight: bold;
}

#use-custom-uid {
    background: #e94560;
    color: white;
}

#use-random-uid {
    background: #0f3460;
    color: #e0e0e0;
}

.error-text {
    color: #ff6b6b;
    font-size: 12px;
    margin-top: 10px;
    min-height: 18px;
}

@media (max-width: 768px) {
    #app {
        flex-direction: row;
    }

    #sidebar {
        position: absolute;
        width: 100%;
        height: 100%;
        z-index: 10;
        transition: transform 0.3s ease;
    }

    #sidebar.hidden {
        transform: translateX(-100%);
    }

    #chat-area {
        width: 100%;
        height: 100%;
    }

    #back-btn {
        display: block;
    }

    .message {
        max-width: 85%;
    }

    #input-area {
        padding: 10px 15px;
    }

    #message-input {
        padding: 10px 15px;
        font-size: 16px;
    }

    #send-btn {
        padding: 10px 18px;
    }
}

@media (max-width: 480px) {
    .sidebar-header h2 {
        font-size: 18px;
    }

    #chat-header {
        padding: 12px 15px;
    }

    #messages {
        padding: 15px;
    }

    .modal-content {
        padding: 20px;
    }
}
