:root {
    --bg-color: #0d0f12;
    --text-primary: #ffffff;
    --text-secondary: #9da3ad;
    --primary-accent: #3A86FF;
    --primary-accent-hover: #266bda;
    --panel-bg: rgba(26, 29, 36, 0.6);
    --panel-border: rgba(255, 255, 255, 0.08);
    --input-bg: rgba(13, 15, 18, 0.8);
    --msg-bg-other: rgba(43, 47, 56, 0.8);
    --msg-bg-self: var(--primary-accent);
    --error-color: #EF476F;
    --sidebar-bg: rgba(20, 22, 28, 0.4);
    --nav-hover: rgba(255, 255, 255, 0.05);
    --nav-active: rgba(58, 134, 255, 0.15);
}

* { box-sizing: border-box; margin: 0; padding: 0; font-family: 'Inter', sans-serif; }

body {
    background-color: var(--bg-color); color: var(--text-primary);
    display: flex; justify-content: center; align-items: center; min-height: 100vh;
    background-image: radial-gradient(circle at 15% 50%, rgba(58, 134, 255, 0.15) 0%, transparent 50%),
                      radial-gradient(circle at 85% 30%, rgba(131, 56, 236, 0.15) 0%, transparent 50%);
    overflow: hidden;
}

#app { width: 100%; max-width: 1000px; padding: 20px; height: 100vh; display: flex; align-items: center; justify-content: center; }
.auth-panel { max-width: 400px; width: 100%; margin: 0 auto; }
.glass-panel { background: var(--panel-bg); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border: 1px solid var(--panel-border); border-radius: 20px; padding: 40px; box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5); transition: all 0.4s ease; }
.view.hidden, .hidden { display: none !important; }

h1, h2 { font-weight: 600; margin-bottom: 8px; letter-spacing: -0.5px; }
.subtitle { color: var(--text-secondary); font-size: 0.95rem; margin-bottom: 30px; }

form { display: flex; flex-direction: column; gap: 20px; }
.input-group { display: flex; flex-direction: column; gap: 8px; text-align: left; }
label { font-size: 0.85rem; color: var(--text-secondary); font-weight: 600; text-transform: uppercase; letter-spacing: 0.5px; }
input { background: var(--input-bg); border: 1px solid var(--panel-border); border-radius: 10px; padding: 14px 16px; color: var(--text-primary); font-size: 1rem; outline: none; transition: all 0.3s ease; }
input:focus { border-color: var(--primary-accent); box-shadow: 0 0 0 3px rgba(58, 134, 255, 0.2); }

button { cursor: pointer; border: none; border-radius: 10px; font-size: 1rem; font-weight: 600; transition: all 0.3s ease; }
.primary-btn { background: var(--primary-accent); color: white; padding: 14px; margin-top: 10px; box-shadow: 0 4px 15px rgba(58, 134, 255, 0.3); }
.primary-btn:hover { background: var(--primary-accent-hover); transform: translateY(-2px); box-shadow: 0 6px 20px rgba(58, 134, 255, 0.4); }
.secondary-btn { background: transparent; color: var(--text-secondary); border: 1px solid var(--panel-border); padding: 8px 16px; font-size: 0.85rem; }
.secondary-btn:hover { color: white; background: rgba(255, 255, 255, 0.1); }

/* Auth Layout */
.toggle-text { margin-top: 25px; font-size: 0.9rem; color: var(--text-secondary); text-align: center; }
.toggle-text a { color: var(--primary-accent); text-decoration: none; font-weight: 600; margin-left: 5px; }
.error-msg { color: var(--error-color); font-size: 0.85rem; margin-top: 15px; text-align: center; min-height: 20px; }

/* Main App Layout */
#app-view { width: 100%; height: 90vh; }
.chat-layout { display: flex; flex-direction: row; height: 100%; padding: 0; overflow: hidden; }

/* Sidebar */
.sidebar { width: 280px; background: var(--sidebar-bg); border-right: 1px solid var(--panel-border); display: flex; flex-direction: column; padding: 20px; flex-shrink: 0; }
.user-profile { 
    display: flex; align-items: center; gap: 15px; padding: 15px; 
    background: var(--nav-active); border-radius: 12px; margin-bottom: 30px; cursor: pointer; transition: all 0.2s;
}
.user-profile:hover { transform: scale(1.02); background: rgba(58, 134, 255, 0.25); }
.avatar-container img { width: 45px; height: 45px; border-radius: 50%; object-fit: cover; border: 2px solid var(--primary-accent); }
.user-info-text { display: flex; flex-direction: column; }
#current-user-badge { font-weight: 600; font-size: 1rem; }
.settings-hint { font-size: 0.75rem; color: var(--text-secondary); margin-top: 2px; }

.chat-nav { flex: 1; display: flex; flex-direction: column; gap: 5px; overflow-y: auto; }
.nav-item { background: transparent; color: var(--text-secondary); text-align: left; padding: 12px 15px; border-radius: 10px; font-size: 0.95rem; display: flex; align-items: center; gap: 10px;}
.nav-item img.nav-avatar { width: 24px; height: 24px; border-radius: 50%; object-fit: cover; }
.nav-item:hover { background: var(--nav-hover); color: var(--text-primary); }
.nav-item.active { background: var(--nav-active); color: var(--primary-accent); font-weight: 600; }
.nav-section-title { font-size: 0.75rem; color: var(--text-secondary); text-transform: uppercase; font-weight: 600; margin: 20px 0 10px 5px; }

.dm-list { list-style: none; display: flex; flex-direction: column; gap: 4px; margin-bottom: 15px; }
.new-chat-form { flex-direction: row; gap: 5px; margin-top: 10px; }
.new-chat-form input { padding: 8px 12px; font-size: 0.85rem; border-radius: 8px; flex: 1; min-width: 0; }
.new-chat-form button { padding: 8px 12px; border-radius: 8px; }
.logout-btn { margin-top: auto; width: 100%; }

/* Content Areas */
.main-content { flex: 1; display: flex; flex-direction: column; padding: 25px; min-width: 0; }
.chat-header { display: flex; justify-content: space-between; align-items: center; padding-bottom: 20px; border-bottom: 1px solid var(--panel-border); margin-bottom: 20px; }

/* Settings View */
.profile-settings-content { display: flex; flex-direction: column; gap: 20px; max-width: 500px; margin: 0 auto; width: 100%; padding-top: 20px;}
.setting-group.centered { align-items: center; }
.avatar-edit-wrapper { position: relative; width: 120px; height: 120px; border-radius: 50%; overflow: hidden; cursor: pointer; border: 3px solid var(--primary-accent); margin-top: 10px;}
#profile-edit-avatar { width: 100%; height: 100%; object-fit: cover; }
.avatar-edit-overlay { position: absolute; bottom: 0; left: 0; right: 0; background: rgba(0,0,0,0.6); color: white; text-align: center; padding: 5px 0; font-size: 0.8rem; transform: translateY(100%); transition: 0.3s; }
.avatar-edit-wrapper:hover .avatar-edit-overlay { transform: translateY(0); }
.id-copy-group { display: flex; gap: 10px; }
.id-copy-group input { flex: 1; cursor: copy; }

/* Chat Box */
#chat-box { 
    flex: 1; 
    overflow-y: auto; 
    margin-bottom: 20px; 
    padding: 20px 10px 20px 20px; /* added inner padding for the background */
    display: flex; 
    flex-direction: column; 
    background-image: url('chat-bg.jpg');
    background-size: cover;
    background-position: center;
    border-radius: 12px;
}
#chat-box::-webkit-scrollbar, .chat-nav::-webkit-scrollbar { width: 6px; }
#chat-box::-webkit-scrollbar-track, .chat-nav::-webkit-scrollbar-track { background: transparent; }
#chat-box::-webkit-scrollbar-thumb, .chat-nav::-webkit-scrollbar-thumb { background: var(--panel-border); border-radius: 10px; }

#messages { list-style-type: none; display: flex; flex-direction: column; gap: 15px; }

.message-wrapper { display: flex; flex-direction: row; gap: 10px; align-items: flex-end; }
.message-wrapper.self { flex-direction: row-reverse; }

.message-avatar { width: 35px; height: 35px; border-radius: 50%; object-fit: cover; flex-shrink: 0; margin-bottom: 5px; }

.message { max-width: 75%; padding: 12px 16px; border-radius: 18px; background: var(--msg-bg-other); align-self: flex-start; animation: slideIn 0.3s ease forwards; }
.message.self { background: var(--msg-bg-self); border-bottom-right-radius: 4px; }
.message-wrapper:not(.self) .message { border-bottom-left-radius: 4px; }
.message.sys { align-self: center; background: transparent; font-size: 0.8rem; color: var(--text-secondary); text-align: center; padding: 0; max-width: 100%;}

.message .meta { font-size: 0.75rem; margin-bottom: 4px; opacity: 0.7; display: flex; justify-content: space-between; gap: 10px; }
.message.self .meta { flex-direction: row-reverse; }
.message .text { font-size: 1rem; line-height: 1.4; word-break: break-word; }

.message-img-content { max-width: 100%; border-radius: 10px; margin-top: 5px; cursor: pointer; transition: transform 0.2s;}
.message-img-content:hover { transform: scale(1.02); }

/* Chat Input */
.attachment-preview { background: var(--input-bg); border: 1px solid var(--panel-border); border-radius: 10px; padding: 10px; margin-bottom: 10px; display: inline-flex; position: relative; }
.attachment-preview img { max-height: 100px; border-radius: 5px; }
#remove-attachment-btn { position: absolute; top: -5px; right: -5px; background: var(--error-color); color: white; width: 20px; height: 20px; border-radius: 50%; display: flex; align-items: center; justify-content: center; font-size: 0.7rem; padding: 0; }

.chat-input-row { display: flex; flex-direction: row; gap: 10px; align-items: center;}
.chat-input-row input[type="text"] { flex: 1; border-radius: 20px; padding: 14px 20px; margin-bottom: 0;}
.attach-btn { width: 50px; height: 50px; border-radius: 50%; font-size: 1.2rem; display: flex; justify-content: center; align-items: center; }
#chat-form button[type="submit"] { background: var(--primary-accent); color: white; border-radius: 50%; width: 50px; height: 50px; flex-shrink: 0; }

@keyframes slideIn { to { opacity: 1; transform: translateY(0); } }

/* Mobile */
@media (max-width: 768px) {
    #app { padding: 5px; }
    .chat-layout { flex-direction: column; }
    .sidebar { width: 100%; height: auto; border-right: none; border-bottom: 1px solid var(--panel-border); padding: 15px; }
    #app-view { height: 98vh; }
}
