* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --bg-primary: #17212b;
    --bg-secondary: #0e1621;
    --bg-tertiary: #242f3d;
    --accent: #5288c1;
    --accent-hover: #6a9fd4;
    --text-primary: #ffffff;
    --text-secondary: #8b9bab;
    --text-muted: #6c7883;
    --border-color: #2b3845;
    --message-out: #2b5278;
    --message-in: #182533;
    --danger: #e53935;
    --success: #4caf50;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background-color: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    overflow: hidden;
}

.screen {
    display: none;
    height: 100vh;
}

.screen.active {
    display: flex;
}

/* ==================== LOGIN SCREEN ==================== */

#login-screen {
    justify-content: center;
    align-items: center;
    background: linear-gradient(135deg, var(--bg-secondary) 0%, var(--bg-primary) 100%);
}

.login-container {
    background: var(--bg-tertiary);
    padding: 40px;
    border-radius: 16px;
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

.login-logo {
    margin-bottom: 30px;
}

.shield-icon {
    font-size: 64px;
    margin-bottom: 16px;
}

.login-logo h1 {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.login-logo p {
    color: var(--text-secondary);
    font-size: 14px;
}

.login-form {
    margin-bottom: 24px;
}

.login-form input {
    width: 100%;
    padding: 14px 16px;
    border: 2px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-secondary);
    color: var(--text-primary);
    font-size: 16px;
    margin-bottom: 16px;
    outline: none;
    transition: border-color 0.2s;
}

.login-form input:focus {
    border-color: var(--accent);
}

.login-form button {
    width: 100%;
    padding: 14px;
    background: var(--accent);
    color: white;
    border: none;
    border-radius: 10px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.login-form button:hover {
    background: var(--accent-hover);
}

.login-form button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.error-message {
    color: var(--danger);
    font-size: 14px;
    margin-top: 12px;
    min-height: 20px;
    display: block;
    word-wrap: break-word;
}

.login-info {
    color: var(--text-muted);
    font-size: 13px;
}

.login-info p {
    margin-bottom: 4px;
}

/* ==================== APP SCREEN ==================== */

.app-container {
    display: flex;
    width: 100%;
    height: 100%;
}

/* Sidebar */
.sidebar {
    width: 320px;
    min-width: 320px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 12px 16px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.logo-small {
    font-size: 18px;
    font-weight: 600;
}

.logout-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 8px;
    border-radius: 8px;
    transition: background 0.2s;
}

.logout-btn:hover {
    background: var(--bg-tertiary);
    color: var(--danger);
}

.search-box {
    padding: 8px 12px;
}

.search-box input {
    width: 100%;
    padding: 10px 14px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 20px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
}

.search-box input::placeholder {
    color: var(--text-muted);
}

.chats-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: background 0.15s;
    border-bottom: 1px solid rgba(255,255,255,0.03);
}

.chat-item:hover {
    background: var(--bg-tertiary);
}

.chat-item.active {
    background: var(--accent);
}

.chat-item .avatar {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    margin-right: 12px;
    flex-shrink: 0;
}

.chat-item .chat-content {
    flex: 1;
    min-width: 0;
}

.chat-item .chat-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 4px;
}

.chat-item .name {
    font-size: 15px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item .time {
    font-size: 12px;
    color: var(--text-muted);
    flex-shrink: 0;
    margin-left: 8px;
}

.chat-item .preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-item .deleted-badge {
    display: inline-block;
    background: var(--danger);
    color: white;
    padding: 2px 6px;
    border-radius: 10px;
    font-size: 11px;
    margin-left: 8px;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
}

.chat-header {
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    align-items: center;
}

.chat-header.hidden {
    display: none;
}

.chat-info {
    display: flex;
    align-items: center;
}

.chat-avatar {
    width: 42px;
    height: 42px;
    border-radius: 50%;
    background: var(--accent);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 16px;
    font-weight: 600;
    margin-right: 12px;
}

.chat-details .chat-name {
    font-size: 16px;
    font-weight: 600;
}

.chat-details .chat-status {
    font-size: 13px;
    color: var(--text-secondary);
}

.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
}

.select-chat-prompt {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    color: var(--text-muted);
}

.prompt-icon {
    font-size: 64px;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* Messages */
.message {
    max-width: 65%;
    margin-bottom: 8px;
    padding: 8px 12px;
    border-radius: 12px;
    position: relative;
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.message.incoming {
    background: var(--message-in);
    align-self: flex-start;
    border-bottom-left-radius: 4px;
}

.message.outgoing {
    background: var(--message-out);
    align-self: flex-end;
    border-bottom-right-radius: 4px;
}

.message.deleted {
    border: 1px dashed var(--danger);
    opacity: 0.7;
}

.message .sender {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    margin-bottom: 4px;
}

.message .text {
    font-size: 14px;
    line-height: 1.4;
    word-wrap: break-word;
}

.message .meta {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 4px;
    gap: 6px;
}

.message .time {
    font-size: 11px;
    color: var(--text-muted);
}

.message .deleted-label {
    font-size: 11px;
    color: var(--danger);
}

/* Media in messages */
.message .media {
    margin: 8px 0;
    max-width: 300px;
    border-radius: 8px;
    overflow: hidden;
    cursor: pointer;
}

.message .media img,
.message .media video {
    max-width: 100%;
    display: block;
}

.message .media-placeholder {
    background: var(--bg-tertiary);
    padding: 16px;
    text-align: center;
    color: var(--text-secondary);
    border-radius: 8px;
}

.message .media-placeholder .icon {
    font-size: 32px;
    margin-bottom: 8px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.modal.hidden {
    display: none;
}

.modal-content {
    position: relative;
    max-width: 90%;
    max-height: 90%;
}

.modal-content img,
.modal-content video {
    max-width: 100%;
    max-height: 90vh;
    border-radius: 8px;
}

.modal-close {
    position: absolute;
    top: -40px;
    right: 0;
    background: none;
    border: none;
    color: white;
    font-size: 32px;
    cursor: pointer;
    padding: 8px;
}

/* Loading */
.loading {
    text-align: center;
    padding: 40px;
    color: var(--text-muted);
}

/* Date divider */
.date-divider {
    text-align: center;
    margin: 16px 0;
    position: relative;
}

.date-divider span {
    background: var(--bg-primary);
    padding: 4px 12px;
    border-radius: 12px;
    font-size: 12px;
    color: var(--text-muted);
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--border-color);
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        position: absolute;
        left: 0;
        top: 0;
        height: 100%;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .message {
        max-width: 85%;
    }
}
