:root {
    --bg-main: #0a0a0c;
    --bg-card: #131316;
    --bg-overlay: rgba(10, 10, 12, 0.8);
    --bg-msg-own: #6366f1;
    --bg-msg-their: #222228;
    
    --text-primary: #ffffff;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    
    --accent: #6366f1;
    --accent-glow: rgba(99, 102, 241, 0.3);
    --danger: #ef4444;
    --success: #10b981;
    
    --border: rgba(255, 255, 255, 0.08);
    --glass: rgba(255, 255, 255, 0.03);
    
    --radius-lg: 24px;
    --radius-md: 16px;
    --radius-sm: 8px;
    
    --font-main: 'Inter', system-ui, sans-serif;
    --font-logo: 'Outfit', sans-serif;
}

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

body {
    background-color: var(--bg-main);
    color: var(--text-primary);
    font-family: var(--font-main);
    height: 100vh;
    overflow: hidden;
}

/* ─── Screens ────────────────────────────────────────────────────────────── */

.screen {
    display: none;
    height: 100vh;
    width: 100vw;
}

.screen.active {
    display: flex;
}

/* ─── Auth Screen ────────────────────────────────────────────────────────── */

#auth-screen {
    align-items: center;
    justify-content: center;
    background: radial-gradient(circle at top right, #1e1b4b, var(--bg-main));
}

.auth-card {
    background: var(--bg-card);
    padding: 40px;
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 450px;
    border: 1px border var(--border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(10px);
}

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

.logo-text {
    font-family: var(--font-logo);
    font-size: 2.5rem;
    font-weight: 800;
    letter-spacing: -2px;
    background: linear-gradient(to bottom right, #818cf8, #c084fc);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    margin-top: 5px;
}

.auth-form {
    display: none;
}

.auth-form.active {
    display: block;
}

.auth-form h2 {
    margin-bottom: 20px;
    font-weight: 600;
}

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

input, textarea {
    width: 100%;
    padding: 14px 18px;
    background: rgba(255, 255, 255, 0.05); /* Lighter, not deep black */
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    color: white;
    font-size: 1rem;
    transition: all 0.3s;
    backdrop-filter: blur(5px);
}

input:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 4px var(--accent-glow);
}

.btn {
    width: 100%;
    padding: 14px;
    border: none;
    border-radius: var(--radius-md);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.btn-primary:hover {
    filter: brightness(1.1);
    transform: translateY(-2px);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--border);
    backdrop-filter: blur(5px);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
    transform: translateY(-2px);
}

.btn-logout {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border: 1px solid rgba(239, 68, 68, 0.2);
}

.btn-logout:hover {
    background: var(--danger);
    color: white;
    transform: translateY(-2px);
}

.auth-switch {
    text-align: center;
    margin-top: 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.auth-switch a {
    color: var(--accent);
    text-decoration: none;
}

/* ─── Messenger Layout ───────────────────────────────────────────────────── */

#messenger-screen {
    display: flex;
}

.sidebar {
    width: 350px;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    background: var(--bg-card);
}

.sidebar-header {
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

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

.avatar {
    width: 44px;
    height: 44px;
    background: linear-gradient(135deg, var(--accent), #a855f7);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
}

.user-details span {
    display: block;
}

.user-details span:first-child {
    font-weight: 600;
}

.status {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.status.online::before {
    content: '';
    display: inline-block;
    width: 8px;
    height: 8px;
    background: var(--success);
    border-radius: 50%;
    margin-right: 5px;
}

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

.header-actions button {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
}

.header-actions button:hover {
    color: white;
}

.sidebar-icon, .input-icon {
    width: 24px;
    height: 24px;
    filter: brightness(0) invert(0.7);
    transition: filter 0.2s;
}

.sidebar-icon:hover, .input-icon:hover {
    filter: brightness(0) invert(1);
}

.icon-white {
    filter: brightness(0) invert(1);
}

.icon-inline {
    filter: brightness(0) invert(0.6);
    vertical-align: middle;
}

.search-bar {
    padding: 0 20px 20px;
}

.search-bar input {
    padding: 10px 15px;
    font-size: 0.9rem;
}

.chats-list {
    flex: 1;
    overflow-y: auto;
}

.chat-item {
    padding: 15px 20px;
    display: flex;
    align-items: center;
    gap: 15px;
    cursor: pointer;
    transition: background 0.2s;
}

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

.chat-item.active {
    background: rgba(99, 102, 241, 0.1);
    border-left: 3px solid var(--accent);
}

.empty-state {
    padding: 60px 20px;
    text-align: center;
    color: var(--text-muted);
    font-size: 0.9rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 15px;
    opacity: 0.5;
}

.empty-state::before {
    content: '';
    display: block;
    width: 60px;
    height: 60px;
    background-image: url('../assets/icons/read.svg');
    background-size: contain;
    background-repeat: no-repeat;
    opacity: 0.2;
    margin-bottom: 10px;
}

.chat-meta {
    flex: 1;
}

.chat-top {
    display: flex;
    justify-content: space-between;
    margin-bottom: 5px;
}

.chat-top h4 {
    font-weight: 600;
    max-width: 140px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.chat-time {
    font-size: 0.75rem;
    color: var(--text-muted);
}

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

/* ─── Chat Area ──────────────────────────────────────────────────────────── */

.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: #000;
    position: relative;
}

.chat-header {
    height: 84px;
    padding: 0 30px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.chat-header.hidden {
    display: none;
}

.messages-container {
    flex: 1;
    padding: 30px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 10px;
    background-image: url('../chat-bg.svg');
    background-size: 400px;
    background-repeat: repeat;
    background-blend-mode: multiply;
}

.welcome-overlay {
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
}

.welcome-overlay h1 {
    font-family: var(--font-logo);
    margin-bottom: 10px;
    opacity: 0.8;
}

.welcome-overlay p {
    color: var(--text-secondary);
    line-height: 1.6;
}

.message {
    max-width: 70%;
    padding: 12px 18px;
    border-radius: 18px;
    font-size: 0.95rem;
    line-height: 1.5;
    position: relative;
    word-break: break-all;
}

.message.own {
    align-self: flex-end;
    background: var(--bg-msg-own);
    border-bottom-right-radius: 4px;
}

.message.their {
    align-self: flex-start;
    background: var(--bg-msg-their);
    border-bottom-left-radius: 4px;
}

.message-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    margin-top: 4px;
    font-size: 0.7rem;
    opacity: 0.7;
}

.message-time {
    color: inherit;
}

.msg-status-icon {
    filter: brightness(0) invert(1);
}

.input-area {
    padding: 20px 30px;
    display: flex;
    align-items: flex-end;
    gap: 15px;
    background: var(--bg-card);
    border-top: 1px solid var(--border);
}

.input-area.hidden { display: none; }

#message-text {
    flex: 1;
    resize: none;
    max-height: 150px;
    background: #000;
    padding: 12px 18px;
}

.send-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--accent);
    color: white;
    border: none;
    cursor: pointer;
}

/* ─── Modals ─────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: var(--bg-overlay);
    backdrop-filter: blur(5px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
}

.modal {
    background: var(--bg-card);
    width: 100%;
    max-width: 500px;
    border-radius: var(--radius-lg);
    border: 1px solid var(--border);
    animation: slideUp 0.3s ease-out;
}

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

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

.modal-body.profile-settings {
    display: flex;
    flex-direction: column;
    gap: 32px; /* Maximum breathing room */
    padding: 40px;
}

.security-info {
    margin-top: 10px;
    padding: 24px;
    background: rgba(0, 0, 0, 0.2);
    border-radius: var(--radius-lg);
    display: flex;
    flex-direction: column;
    gap: 20px;
    border: 1px solid var(--border);
}

.security-info h4 {
    display: flex;
    align-items: center;
    gap: 10px;
    color: var(--accent);
}

.close-modal {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    font-size: 1.5rem;
    cursor: pointer;
}

/* ─── Utils ──────────────────────────────────────────────────────────────── */

.toast {
    position: fixed;
    top: 30px; /* Moved to top */
    right: 30px; /* Moved to right */
    background: rgba(16, 185, 129, 0.1); /* Success background as default */
    color: var(--success);
    padding: 16px 28px;
    border-radius: var(--radius-md);
    border: 1px solid var(--success);
    backdrop-filter: blur(10px);
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275), opacity 0.4s;
    z-index: 2000;
    opacity: 0;
    transform: translateY(-20px);
    pointer-events: none;
}

.toast.show { opacity: 1; transform: translateY(0); }

.toast.error {
    background: rgba(239, 68, 68, 0.1);
    color: var(--danger);
    border-color: var(--danger);
}
