:root {
    --primary: #6C3CE1;
    --primary-dark: #5428C8;
    --primary-light: #8B5CF6;
    --bg-dark: #0F0F1A;
    --bg-panel: #1A1A2E;
    --bg-chat: #12121F;
    --bg-input: #252540;
    --bg-bubble-out: #6C3CE1;
    --bg-bubble-in: #252540;
    --text: #E8E8F0;
    --text-muted: #8888AA;
    --text-bubble: #FFFFFF;
    --border: #2A2A45;
    --online: #22C55E;
    --danger: #EF4444;
    --radius: 12px;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg-dark);
    color: var(--text);
    height: 100dvh;
    overflow: hidden;
}

/* === AUTH SCREEN === */
#auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100dvh;
    background: linear-gradient(135deg, var(--bg-dark) 0%, #1a1035 100%);
}

.auth-card {
    background: var(--bg-panel);
    border-radius: 20px;
    padding: 40px;
    width: 360px;
    text-align: center;
    border: 1px solid var(--border);
}

.auth-card .logo {
    width: 80px;
    height: 80px;
    margin: 0 auto 16px;
}

.auth-card h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    background: linear-gradient(135deg, var(--primary-light), #C084FC);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-card p {
    color: var(--text-muted);
    font-size: 14px;
    margin-bottom: 24px;
}

.auth-input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    font-size: 15px;
    margin-bottom: 12px;
    outline: none;
    transition: border-color 0.2s;
}

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

.auth-btn {
    width: 100%;
    padding: 14px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius);
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
    margin-bottom: 8px;
}

.auth-btn:hover { background: var(--primary-dark); }
.auth-btn:disabled { opacity: 0.5; cursor: not-allowed; }

.auth-btn.secondary {
    background: transparent;
    border: 1px solid var(--border);
}

.auth-btn.secondary:hover { background: var(--bg-input); }

.remember-me {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    font-size: 13px;
    color: var(--text-muted);
    margin: 12px 0 4px;
    cursor: pointer;
    user-select: none;
}
.remember-me input {
    accent-color: var(--primary);
    width: 16px;
    height: 16px;
    cursor: pointer;
}

.auth-error {
    color: var(--danger);
    font-size: 13px;
    margin-top: 8px;
    min-height: 20px;
}

/* === MESSENGER LAYOUT === */
#app-screen {
    display: none;
    height: 100dvh;
}

.messenger {
    display: flex;
    height: 100%;
}

/* === SIDEBAR === */
.sidebar {
    width: 320px;
    background: var(--bg-panel);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
}

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

.sidebar-header h2 {
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-header h2 img { width: 28px; height: 28px; }

.sidebar-header .username {
    font-size: 13px;
    color: var(--text-muted);
}

.btn-logout {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 20px;
    padding: 4px 8px;
    border-radius: 8px;
}
.btn-logout:hover { background: var(--bg-input); }

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

.user-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px;
    border-radius: var(--radius);
    cursor: pointer;
    transition: background 0.15s;
}

.user-item:hover, .user-item.active {
    background: var(--bg-input);
}

.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
}

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

.user-info .name { font-weight: 600; font-size: 15px; }
.user-info .preview {
    color: var(--text-muted);
    font-size: 13px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* === CHAT AREA === */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-chat);
}

.chat-placeholder {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 16px;
    flex-direction: column;
    gap: 12px;
}

.chat-placeholder img { width: 64px; opacity: 0.3; }

.chat-header {
    padding: 14px 20px;
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-panel);
}

.chat-header .name { font-weight: 600; font-size: 16px; }
.chat-header .status { font-size: 12px; color: var(--text-muted); }

.encryption-badge {
    margin-left: auto;
    font-size: 11px;
    color: var(--online);
    display: flex;
    align-items: center;
    gap: 4px;
    background: rgba(34, 197, 94, 0.1);
    padding: 4px 10px;
    border-radius: 20px;
    cursor: pointer;
    transition: background 0.2s;
}
.encryption-badge:hover {
    background: rgba(34, 197, 94, 0.2);
}

/* Safety Number Modal */
.safety-modal {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}
.safety-card {
    background: var(--bg-panel);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 32px;
    width: 340px;
    text-align: center;
}
.safety-card h3 {
    color: var(--online);
    margin-bottom: 8px;
}
.safety-desc {
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 20px;
    line-height: 1.4;
}
.safety-number {
    font-family: 'Courier New', monospace;
    font-size: 20px;
    letter-spacing: 3px;
    color: var(--text);
    background: var(--bg-dark);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 16px;
    margin: 0 auto 12px;
    word-break: break-all;
    line-height: 1.6;
    user-select: all;
}
.safety-users {
    display: flex;
    justify-content: space-between;
    font-size: 12px;
    color: var(--text-muted);
    padding: 0 4px;
}

/* === MESSAGES === */
.messages {
    flex: 1;
    overflow-y: auto;
    padding: 16px 20px;
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.msg {
    max-width: 70%;
    padding: 10px 14px;
    border-radius: 16px;
    font-size: 15px;
    line-height: 1.45;
    word-wrap: break-word;
    position: relative;
}

.msg.out {
    align-self: flex-end;
    background: var(--bg-bubble-out);
    color: var(--text-bubble);
    border-bottom-right-radius: 4px;
}

.msg.in {
    align-self: flex-start;
    background: var(--bg-bubble-in);
    color: var(--text);
    border-bottom-left-radius: 4px;
}

.msg .time {
    font-size: 11px;
    opacity: 0.6;
    margin-top: 4px;
    text-align: right;
}

.msg .media-preview {
    max-width: 100%;
    max-height: 300px;
    border-radius: 8px;
    margin-bottom: 4px;
    cursor: pointer;
}

.msg audio {
    max-width: 100%;
}

.typing-indicator {
    color: var(--text-muted);
    font-size: 13px;
    padding: 4px 20px;
    font-style: italic;
    min-height: 24px;
}

/* === INPUT BAR === */
.input-bar {
    padding: 12px 16px;
    border-top: 1px solid var(--border);
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-panel);
}

.input-bar textarea {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    color: var(--text);
    padding: 12px 14px;
    font-size: 15px;
    font-family: inherit;
    resize: none;
    outline: none;
    max-height: 120px;
    min-height: 44px;
    line-height: 1.4;
}

.input-bar textarea:focus { border-color: var(--primary); }

.input-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: background 0.15s;
}

.btn-send {
    background: var(--primary);
    color: white;
}
.btn-send:hover { background: var(--primary-dark); }

.btn-attach, .btn-voice {
    background: var(--bg-input);
    color: var(--text-muted);
}
.btn-attach:hover, .btn-voice:hover { background: var(--border); color: var(--text); }

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

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

/* File input hidden */
#file-input { display: none; }

/* === MOBILE === */
@media (max-width: 768px) {
    .sidebar { width: 100%; }
    .chat-area { display: none; }
    .messenger.chat-open .sidebar { display: none; }
    .messenger.chat-open .chat-area { display: flex; }

    .chat-header .btn-back {
        display: block;
        background: none;
        border: none;
        color: var(--text);
        font-size: 20px;
        cursor: pointer;
        padding: 4px 8px;
    }

    .msg { max-width: 85%; }
}

@media (min-width: 769px) {
    .chat-header .btn-back { display: none; }
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }
