:root {
    --bg: #0f0f1e;
    --sidebar: #161625;
    --panel: #1e1e30;
    --input-bg: #252542;
    --text: #ffffff;
    --text-dim: #8888aa;
    --accent: #87CEEB;
    --accent-hover: #5ca1cc;
    --bubble-out: #2d5a7b;
    --bubble-in: #252542;
    --error: #ff4444;
    --success: #4CAF50;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); height: 100vh; overflow: hidden; }
.screen { display: none; height: 100%; width: 100%; }
.screen.active { display: flex; }
.view-container { flex: 1; display: flex; flex-direction: column; height: 100%; overflow-y: auto; background: var(--bg); z-index: 1; }

/* === TOAST NOTIFICATIONS === */
#toast-container { position: fixed; top: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 10px; pointer-events: none; }
.toast { pointer-events: auto; padding: 12px 16px; border-radius: 12px; color: white; font-size: 14px; font-weight: 500; box-shadow: 0 4px 12px rgba(0,0,0,0.4); animation: toastIn 0.3s ease; max-width: 320px; display: flex; align-items: center; gap: 8px; backdrop-filter: blur(8px); }
.toast.success { background: var(--success); }
.toast.info { background: var(--accent); color: #0f0f1e; }
.toast.hard-error { background: var(--error); animation: toastIn 0.3s ease, pulseBorder 2s infinite; }
.toast-close { margin-left: auto; cursor: pointer; opacity: 0.7; font-size: 18px; line-height: 1; }
.toast-close:hover { opacity: 1; }
.toast.fade-out { animation: toastOut 0.3s ease forwards; }
@keyframes toastIn { from { transform: translateX(120%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }
@keyframes pulseBorder { 0%,100% { box-shadow: 0 0 0 0 rgba(255,68,68,0.4); } 50% { box-shadow: 0 0 0 8px rgba(255,68,68,0); } }

/* === INLINE FIELD ERRORS === */
.field-error { color: var(--error); font-size: 12px; margin-top: 4px; margin-bottom: 8px; padding-left: 4px; animation: fadeIn 0.2s; min-height: 16px; }
.auth-input.error, .profile-field-input.error { border-color: var(--error) !important; background: rgba(255,68,68,0.05) !important; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

/* === AUTH SCREENS === */
.auth-container { width: 100%; max-width: 400px; margin: auto; padding: 20px; display: flex; flex-direction: column; justify-content: center; }
.auth-header { text-align: center; margin-bottom: 30px; }
.brand-title { color: var(--accent); margin: 0; font-size: 32px; }
.brand-tagline { color: var(--text-dim); font-style: italic; margin-top: 5px; }
.auth-form { background: var(--panel); padding: 25px; border-radius: 20px; box-shadow: 0 10px 30px rgba(0,0,0,0.5); }
.step-title { text-align: center; margin-bottom: 15px; color: var(--text); }
.auth-input { width: 100%; padding: 14px; margin: 8px 0; background: var(--input-bg); border: 1px solid transparent; color: white; border-radius: 12px; font-size: 16px; }
.auth-input:focus { outline: none; border-color: var(--accent); }
.username-status { font-size: 13px; margin: 5px 0 10px; padding: 8px; border-radius: 8px; text-align: center; }
.username-status.available { color: var(--success); background: rgba(76, 175, 80, 0.15); }
.username-status.taken { color: var(--error); background: rgba(255, 68, 68, 0.15); }
.username-status.checking { color: var(--text-dim); background: rgba(136, 136, 170, 0.1); }
.primary-btn { width: 100%; padding: 14px; border: none; border-radius: 12px; cursor: pointer; background: var(--accent); color: #0f0f1e; font-weight: bold; font-size: 16px; margin-top: 15px; transition: 0.2s; }
.primary-btn:hover { background: var(--accent-hover); }
.register-link { text-align: center; margin-top: 20px; color: var(--text-dim); }
.register-link a { color: var(--accent); text-decoration: none; font-weight: bold; }
.avatar-upload { margin: 15px 0; text-align: center; }
.avatar-label { cursor: pointer; }
.avatar-placeholder { background: var(--bg); padding: 15px; border-radius: 8px; border: 2px dashed var(--accent); color: var(--text-dim); }
.avatar-preview { width: 100px; height: 100px; border-radius: 50%; object-fit: cover; margin: 10px auto; display: block; border: 3px solid var(--accent); }

/* === MAIN LAYOUT === */
.side-menu { position: fixed; left: -280px; top: 0; width: 280px; height: 100vh; background: var(--sidebar); z-index: 1000; transition: left 0.3s; box-shadow: 2px 0 15px rgba(0,0,0,0.5); }
.side-menu.open { left: 0; }
.menu-header { padding: 20px; background: var(--panel); display: flex; align-items: center; }
.menu-avatar img { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; }
.menu-user-info { margin-left: 15px; flex: 1; }
.menu-displayname { font-weight: bold; font-size: 16px; }
.menu-username { color: var(--text-dim); font-size: 13px; }
.menu-close { background: none; border: none; color: var(--text); font-size: 24px; cursor: pointer; }
.menu-item { padding: 15px 20px; display: flex; align-items: center; cursor: pointer; border-bottom: 1px solid #333; }
.menu-item:hover { background: var(--panel); }
.menu-item span:first-child { margin-right: 15px; font-size: 18px; }
.menu-overlay { display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 999; }
.menu-overlay.active { display: block; }

/* === HEADER (FIXED) === */
.header { 
    position: relative; 
    padding: 15px 20px; 
    background: var(--panel); 
    border-bottom: 1px solid #333; 
    display: flex; 
    align-items: center; 
    height: 60px; 
}
.menu-btn { 
    background: none; 
    border: none; 
    color: var(--text); 
    cursor: pointer; 
    padding: 5px;
    z-index: 10;
}
.header-title { 
    flex: 1; 
    text-align: center; 
    pointer-events: none;
}
.brand { color: var(--accent); font-size: 20px; font-weight: bold; }
.tagline { color: var(--text-dim); font-size: 12px; font-style: italic; }

/* === CHAT LIST & SEARCH === */
.search-container { padding: 10px 20px; position: sticky; top: 0; background: var(--bg); z-index: 5; }
#search-input { width: 100%; padding: 12px 15px; background: var(--panel); border: none; border-radius: 20px; color: white; font-size: 15px; }
#search-input:focus { outline: 2px solid var(--accent); background: var(--input-bg); }
.chat-list { flex: 1; overflow-y: auto; }
.chat-item { padding: 12px 20px; display: flex; align-items: center; cursor: pointer; border-bottom: 1px solid #222; }
.chat-item:hover { background: var(--panel); }
.chat-avatar { width: 50px; height: 50px; border-radius: 50%; object-fit: cover; margin-right: 15px; }
.chat-info { flex: 1; min-width: 0; }
.chat-displayname { font-weight: 600; margin-bottom: 4px; }
.chat-preview { color: var(--text-dim); font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

/* === CHAT VIEW === */
.chat-header { padding: 15px 20px; background: var(--panel); border-bottom: 1px solid #333; display: flex; align-items: center; position: sticky; top: 0; z-index: 5; }
.back-btn { background: none; border: none; color: var(--text); font-size: 24px; cursor: pointer; padding: 5px; margin-right: 10px; }
.chat-header-info { flex: 1; display: flex; align-items: center; }
.chat-header-avatar { width: 40px; height: 40px; border-radius: 50%; margin-right: 12px; object-fit: cover; }
.chat-header-displayname { font-weight: 600; }
.chat-header-status { color: var(--text-dim); font-size: 13px; }
.messages-area { flex: 1; padding: 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }
.message { max-width: 75%; padding: 10px 14px; border-radius: 16px; font-size: 15px; line-height: 1.4; word-wrap: break-word; }
.message.out { background: var(--bubble-out); margin-left: auto; border-bottom-right-radius: 4px; }
.message.in { background: var(--bubble-in); margin-right: auto; border-bottom-left-radius: 4px; }
.input-area { padding: 15px 20px; background: var(--panel); display: flex; gap: 10px; align-items: center; }
#msg-input { flex: 1; padding: 12px 15px; background: var(--input-bg); border: none; border-radius: 20px; color: white; font-size: 15px; }
#msg-input:focus { outline: 2px solid var(--accent); }
.send-btn { width: 45px; height: 45px; border-radius: 50%; border: none; background: var(--accent); color: #0f0f1e; cursor: pointer; font-size: 20px; }

/* === SETTINGS & PROFILE === */
.settings-header { position: sticky; top: 0; z-index: 10; padding: 15px 20px; background: var(--panel); border-bottom: 1px solid #333; display: flex; align-items: center; font-weight: 600; font-size: 18px; }
.settings-content { flex: 1; padding: 20px; max-width: 700px; margin: 0 auto; width: 100%; }
.settings-section { background: var(--panel); border-radius: 16px; overflow: hidden; margin-bottom: 20px; }
.settings-item { padding: 15px 20px; display: flex; align-items: center; cursor: pointer; border-bottom: 1px solid #333; }
.settings-item:last-child { border-bottom: none; }
.settings-icon { font-size: 22px; margin-right: 15px; width: 30px; text-align: center; }
.settings-item-info { flex: 1; }
.settings-subtitle { color: var(--text-dim); font-size: 13px; margin-top: 3px; }

.profile-content { padding: 0; max-width: 700px; margin: 0 auto; width: 100%; }
.profile-header-section { text-align: center; padding: 30px 20px; background: var(--panel); border-bottom: 1px solid #333; }
.profile-avatar-large { width: 120px; height: 120px; border-radius: 50%; object-fit: cover; margin-bottom: 15px; border: 3px solid var(--accent); }
.profile-displayname-large { font-size: 22px; font-weight: bold; margin: 5px 0; }
.profile-username-large { color: var(--accent); font-size: 15px; margin-bottom: 5px; }
.profile-bio-large { color: var(--text-dim); font-size: 14px; max-width: 80%; margin: 0 auto; line-height: 1.4; }

.profile-fields-section { padding: 25px 20px; max-width: 600px; margin: 0 auto; width: 100%; }
.profile-field-group { margin-bottom: 20px; }
.profile-field-label { color: var(--accent); font-size: 13px; font-weight: bold; margin-bottom: 8px; display: block; text-transform: uppercase; }
.profile-field-input { width: 100%; padding: 14px; background: var(--input-bg); border: none; border-radius: 14px; color: white; font-size: 16px; }
.profile-field-input:focus { outline: 2px solid var(--accent); background: #2a2a45; }

/* === ABOUT PAGE === */
.about-content { padding: 30px 20px; text-align: center; max-width: 700px; margin: 0 auto; width: 100%; }
.about-text { text-align: left; margin-top: 20px; background: var(--panel); padding: 20px; border-radius: 16px; }
.about-text h3 { color: var(--accent); margin: 15px 0 10px; font-size: 16px; }
.about-text p { color: #ccc; margin: 6px 0; font-size: 15px; line-height: 1.5; }

/* === CROP MODAL (WITH ZOOM) === */
.avatar-crop-modal { position: fixed; inset: 0; background: rgba(0,0,0,0.9); z-index: 30000; display: none; align-items: center; justify-content: center; }
.avatar-crop-modal.show { display: flex; }
.crop-modal-content { background: var(--panel); border-radius: 16px; padding: 20px; max-width: 90vw; width: 350px; text-align: center; }
.crop-title { margin-bottom: 15px; }
.crop-container { position: relative; width: 100%; height: 250px; overflow: hidden; border: 1px solid #444; border-radius: 8px; margin-bottom: 15px; display: flex; align-items: center; justify-content: center; }
.crop-container img { max-width: 100%; max-height: 100%; object-fit: contain; }
.crop-area { position: absolute; top: 50%; left: 50%; width: 120px; height: 120px; border: 2px solid white; box-shadow: 0 0 0 9999px rgba(0,0,0,0.5); transform: translate(-50%,-50%); cursor: move; border-radius: 50%; z-index: 10; }
.crop-controls { display: flex; gap: 10px; justify-content: center; align-items: center; }
.crop-cancel-btn, .crop-confirm-btn { padding: 10px 20px; border: none; border-radius: 8px; cursor: pointer; font-weight: bold; }
.crop-cancel-btn { background: transparent; border: 1px solid var(--text-dim); color: var(--text-dim); }
.crop-confirm-btn { background: var(--accent); color: #0f0f1e; }

/* === RESPONSIVE DESKTOP === */
@media(min-width:900px){
    .side-menu { position: relative; left: 0!important; width: 320px; height: 100%; box-shadow: none; border-right: 1px solid #333; flex-shrink: 0; }
    .menu-overlay { display: none!important; }
    .menu-btn { display: none; }
    .main-screen { flex-direction: row; }
    #view-messenger, #view-chat, #view-settings, #view-account, #view-profile, #view-info { display: flex!important; flex-direction: column; flex: 1; }
    .back-btn { display: none; }
}