/* MegaChat Main Styles - WhatsApp Like Design */

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

:root {
    --primary: #075E54;
    --primary-dark: #054a3f;
    --primary-light: #128C7E;
    --secondary: #34B7F1;
    --accent: #25D366;
    --bg-primary: #111b21;
    --bg-secondary: #202c33;
    --bg-tertiary: #2a3942;
    --bg-header: #202c33;
    --text-primary: #e9edef;
    --text-secondary: #8696a0;
    --text-muted: #667781;
    --border: #2a3942;
    --border-light: #3a4a55;
    --danger: #dc2c2c;
    --success: #25D366;
    --warning: #ffbc00;
    --info: #34B7F1;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 8px 24px rgba(0,0,0,0.4);
    --radius: 12px;
    --radius-sm: 8px;
    --radius-lg: 18px;
    --transition: all 0.2s ease;
    --font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}

body {
    font-family: var(--font-family);
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    width: 100vw;
}

/* Scrollbar */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #374248; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #4a5a66; }

/* Screens */
.screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    transition: var(--transition);
}
.screen.hidden { display: none !important; }

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes slideUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes pulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.05); }
}
@keyframes spin {
    to { transform: rotate(360deg); }
}

/* ========== AUTH SCREEN ========== */
#auth-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #075E54 0%, #128C7E 100%);
    padding: 20px;
}

.auth-container {
    width: 100%;
    max-width: 420px;
    background: rgba(32, 44, 51, 0.95);
    backdrop-filter: blur(20px);
    border-radius: 32px;
    padding: 40px 32px;
    text-align: center;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(255,255,255,0.1);
    animation: slideUp 0.5s ease;
}

.logo {
    margin-bottom: 16px;
}

.auth-container h2 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.auth-container .subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 32px;
}

.auth-form {
    display: flex;
    flex-direction: column;
    gap: 18px;
}

.auth-form.hidden { display: none; }

.input-group {
    text-align: left;
}

.input-group label {
    display: block;
    margin-bottom: 6px;
    color: var(--text-secondary);
    font-size: 13px;
    font-weight: 500;
}

.auth-form input {
    width: 100%;
    padding: 14px 16px;
    background: var(--bg-tertiary);
    border: 1.5px solid var(--border);
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    transition: var(--transition);
}

.auth-form input:focus {
    border-color: var(--primary);
}

.password-strength {
    margin-top: 8px;
    height: 4px;
    background: var(--bg-tertiary);
    border-radius: 2px;
    overflow: hidden;
}

.strength-bar {
    height: 100%;
    width: 0;
    transition: var(--transition);
}

.strength-bar.weak { width: 33%; background: var(--danger); }
.strength-bar.medium { width: 66%; background: var(--warning); }
.strength-bar.strong { width: 100%; background: var(--success); }

.btn-primary {
    width: 100%;
    padding: 14px;
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: white;
    border: none;
    border-radius: 40px;
    font-size: 16px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 15px rgba(7,94,84,0.4);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    padding: 12px;
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    border-radius: 40px;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    background: var(--bg-hover);
}

.btn-danger {
    padding: 12px;
    background: var(--danger);
    color: white;
    border: none;
    border-radius: 40px;
    cursor: pointer;
}

.divider {
    display: flex;
    align-items: center;
    gap: 15px;
    color: var(--text-muted);
    font-size: 13px;
    margin: 10px 0;
}

.divider::before,
.divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}

.forgot-password {
    color: var(--secondary);
    text-decoration: none;
    font-size: 13px;
}

.terms {
    margin-top: 24px;
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.terms a {
    color: var(--secondary);
    text-decoration: none;
}

/* ========== MAIN APP LAYOUT ========== */
#main-app {
    display: flex;
    height: 100vh;
    width: 100vw;
}

/* Sidebar */
.sidebar {
    width: 400px;
    min-width: 300px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
}

.sidebar-header {
    padding: 12px 16px;
    background: var(--bg-header);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
}

.user-info {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
    padding: 4px;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.user-info:hover {
    background: var(--bg-tertiary);
}

.user-avatar {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    font-weight: 600;
    color: white;
    position: relative;
    overflow: hidden;
}

.user-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.user-details .name {
    font-weight: 600;
    font-size: 16px;
}

.user-details .status-text {
    font-size: 12px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.header-actions {
    display: flex;
    gap: 8px;
}

.icon-btn {
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    border-radius: 50%;
    transition: var(--transition);
}

.icon-btn:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Search Bar */
.search-bar {
    padding: 8px 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.search-wrapper {
    position: relative;
}

.search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    font-size: 16px;
}

.search-bar input {
    width: 100%;
    padding: 10px 14px 10px 42px;
    background: var(--bg-tertiary);
    border: none;
    border-radius: 24px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.search-bar input:focus {
    background: var(--bg-primary);
}

.search-bar input::placeholder {
    color: var(--text-muted);
}

/* Tabs */
.tabs {
    display: flex;
    padding: 0 16px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 14px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-weight: 500;
    font-size: 14px;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
}

.tab:hover {
    color: var(--text-primary);
}

.tab.active {
    color: var(--primary);
}

.tab.active::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 20%;
    width: 60%;
    height: 2px;
    background: var(--primary);
    border-radius: 2px;
    animation: fadeIn 0.3s ease;
}

/* List Containers */
.list-container {
    flex: 1;
    overflow-y: auto;
}

.list-container.hidden {
    display: none;
}

/* Chat Items */
.chat-item {
    display: flex;
    align-items: center;
    padding: 12px 16px;
    cursor: pointer;
    transition: var(--transition);
    gap: 12px;
    border-bottom: 1px solid var(--border);
}

.chat-item:hover {
    background: var(--bg-tertiary);
}

.chat-item.active {
    background: var(--bg-tertiary);
}

.chat-avatar {
    width: 52px;
    height: 52px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 22px;
    font-weight: 600;
    color: white;
    flex-shrink: 0;
    overflow: hidden;
}

.chat-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.chat-info {
    flex: 1;
    min-width: 0;
}

.chat-name-row {
    display: flex;
    justify-content: space-between;
    margin-bottom: 4px;
}

.chat-name {
    font-weight: 600;
    font-size: 15px;
}

.chat-time {
    font-size: 11px;
    color: var(--text-muted);
}

.chat-preview {
    font-size: 13px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.unread-badge {
    background: var(--primary);
    color: white;
    font-size: 11px;
    font-weight: 600;
    padding: 2px 6px;
    border-radius: 12px;
    margin-left: 8px;
}

/* Chat Area */
.chat-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--bg-primary);
    position: relative;
}

.chat-header {
    padding: 10px 16px;
    background: var(--bg-header);
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.chat-header-info {
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.chat-header-info .chat-avatar {
    width: 40px;
    height: 40px;
    font-size: 18px;
}

.header-text .name {
    font-weight: 600;
    font-size: 16px;
}

.header-text .subtitle {
    font-size: 12px;
    color: var(--text-secondary);
}

.header-text .subtitle.typing {
    color: var(--primary);
}

.header-actions-right {
    display: flex;
    gap: 8px;
}

.header-actions-right button {
    width: 38px;
    height: 38px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 20px;
    cursor: pointer;
    border-radius: 50%;
    transition: var(--transition);
}

.header-actions-right button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

/* Messages Container */
.messages-container {
    flex: 1;
    overflow-y: auto;
    padding: 16px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.date-separator {
    display: flex;
    justify-content: center;
    margin: 16px 0;
}

.date-separator span {
    background: var(--bg-tertiary);
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 11px;
    color: var(--text-secondary);
}

.message {
    max-width: 65%;
    padding: 8px 12px;
    border-radius: 16px;
    position: relative;
    animation: fadeIn 0.2s ease;
    word-wrap: break-word;
}

.message.sent {
    align-self: flex-end;
    background: var(--primary);
    border-bottom-right-radius: 4px;
}

.message.received {
    align-self: flex-start;
    background: var(--bg-tertiary);
    border-bottom-left-radius: 4px;
}

.message-content {
    font-size: 14px;
    line-height: 1.45;
}

.message-meta {
    display: flex;
    justify-content: flex-end;
    gap: 4px;
    margin-top: 4px;
    font-size: 10px;
    opacity: 0.7;
}

.message-status.sent { color: var(--text-muted); }
.message-status.delivered { color: var(--text-muted); }
.message-status.read { color: var(--secondary); }

/* Input Area */
.input-area {
    padding: 12px 16px;
    background: var(--bg-header);
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
    align-items: center;
}

.input-actions {
    display: flex;
    gap: 8px;
}

.input-actions button {
    width: 40px;
    height: 40px;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 22px;
    cursor: pointer;
    border-radius: 50%;
    transition: var(--transition);
}

.input-actions button:hover {
    background: var(--bg-tertiary);
    color: var(--text-primary);
}

.message-input-wrapper {
    flex: 1;
    background: var(--bg-tertiary);
    border-radius: 24px;
    padding: 8px 16px;
}

.message-input {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    font-size: 15px;
    outline: none;
    resize: none;
    font-family: inherit;
}

.message-input::placeholder {
    color: var(--text-muted);
}

.input-send-btn {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--primary);
    border: none;
    color: white;
    font-size: 20px;
    cursor: pointer;
    transition: var(--transition);
}

.input-send-btn:hover {
    background: var(--primary-dark);
    transform: scale(1.05);
}

/* Empty State */
.empty-state {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 40px;
}

.empty-icon {
    font-size: 80px;
    margin-bottom: 24px;
    opacity: 0.8;
}

.empty-state h2 {
    font-size: 24px;
    margin-bottom: 12px;
}

.empty-state p {
    color: var(--text-secondary);
}

/* Profile Modal */
.profile-modal {
    max-width: 400px;
}

.profile-avatar-section {
    display: flex;
    justify-content: center;
    margin-bottom: 24px;
}

.profile-avatar {
    width: 120px;
    height: 120px;
    border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    position: relative;
    cursor: pointer;
    overflow: hidden;
}

.profile-avatar img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.avatar-edit-btn {
    position: absolute;
    bottom: 0;
    right: 0;
    width: 36px;
    height: 36px;
    background: var(--primary);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    border: 3px solid var(--bg-secondary);
}

.profile-field {
    margin-bottom: 20px;
}

.profile-field label {
    display: block;
    margin-bottom: 8px;
    color: var(--text-secondary);
    font-size: 13px;
}

.profile-field input {
    width: 100%;
    padding: 12px;
    background: var(--bg-tertiary);
    border: 1px solid var(--border);
    border-radius: 12px;
    color: var(--text-primary);
    font-size: 15px;
}

/* Wallpaper Modal */
.wallpaper-options {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 16px;
}

.wallpaper-option {
    text-align: center;
    cursor: pointer;
    padding: 12px;
    border-radius: 12px;
    transition: var(--transition);
}

.wallpaper-option:hover {
    background: var(--bg-tertiary);
}

.wallpaper-preview {
    width: 100%;
    height: 120px;
    border-radius: 12px;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 32px;
}

.default-bg {
    background: url('data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI4MCIgaGVpZ2h0PSI4MCIgdmlld0JveD0iMCAwIDQwIDQwIj48Y2lyY2xlIGN4PSIyMCIgY3k9IjIwIiByPSIxIiBmaWxsPSIjMjA0NjNlIiBmaWxsLW9wYWNpdHk9IjAuMDYiLz48L3N2Zz4=');
    background-repeat: repeat;
}

.dark-bg {
    background: #0a0a0a;
}

.light-bg {
    background: #e8e8e8;
}

.upload-bg {
    background: var(--bg-tertiary);
}

/* Lock Screen */
.lock-screen {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--bg-primary);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
}

.lock-screen.hidden {
    display: none;
}

.lock-container {
    text-align: center;
    padding: 40px;
}

.lock-avatar {
    margin-bottom: 24px;
}

.lock-avatar .user-avatar {
    width: 100px;
    height: 100px;
    font-size: 48px;
    margin: 0 auto;
}

.lock-name {
    font-size: 24px;
    font-weight: 600;
    margin-bottom: 8px;
}

.lock-prompt {
    color: var(--text-secondary);
    margin-bottom: 32px;
}

.pin-display {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-bottom: 32px;
}

.pin-display span {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: var(--border);
    transition: var(--transition);
}

.pin-display span.filled {
    background: var(--primary);
}

.pin-keypad {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-bottom: 24px;
}

.pin-row {
    display: flex;
    justify-content: center;
    gap: 20px;
}

.pin-btn {
    width: 70px;
    height: 70px;
    border-radius: 50%;
    background: var(--bg-tertiary);
    border: none;
    color: var(--text-primary);
    font-size: 28px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.pin-btn:hover {
    background: var(--bg-hover);
    transform: scale(1.05);
}

.pin-btn:active {
    transform: scale(0.95);
}

.fingerprint-btn {
    background: var(--primary);
    color: white;
}

.delete-btn {
    font-size: 24px;
}

.logout-link {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 14px;
}

/* Settings Modal */
.settings-content {
    max-width: 450px;
}

.settings-section {
    margin-bottom: 24px;
}

.settings-section h3 {
    font-size: 14px;
    color: var(--primary);
    margin-bottom: 16px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.setting-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 0;
    border-bottom: 1px solid var(--border);
}

.setting-item:last-child {
    border-bottom: none;
}

.setting-item label {
    font-size: 15px;
}

.setting-item select {
    background: var(--bg-tertiary);
    color: var(--text-primary);
    border: 1px solid var(--border);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 14px;
}

.danger-zone {
    background: rgba(220,44,44,0.1);
    border-radius: 16px;
    padding: 16px;
    margin-top: 16px;
}

.danger-zone h3 {
    color: var(--danger);
}

/* Toggle Switch */
.toggle-switch {
    width: 48px;
    height: 24px;
    background: var(--bg-tertiary);
    border-radius: 12px;
    cursor: pointer;
    position: relative;
    transition: var(--transition);
    border: 2px solid var(--border);
}

.toggle-switch.active {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle-switch::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    transition: var(--transition);
}

.toggle-switch.active::after {
    left: 26px;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 3000;
    backdrop-filter: blur(5px);
}

.modal.hidden {
    display: none;
}

.modal-content {
    background: var(--bg-secondary);
    border-radius: 24px;
    max-width: 500px;
    width: 90%;
    max-height: 85vh;
    overflow-y: auto;
    animation: slideUp 0.3s ease;
}

.modal-header {
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-header h2 {
    font-size: 20px;
}

.modal-close {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--bg-tertiary);
}

.modal-body {
    padding: 20px 24px;
}

.modal-footer {
    padding: 16px 24px 24px;
    display: flex;
    justify-content: flex-end;
    gap: 12px;
}

/* Context Menu */
.context-menu {
    position: absolute;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 8px 0;
    min-width: 200px;
    z-index: 4000;
    box-shadow: var(--shadow-lg);
    animation: fadeIn 0.15s ease;
}

.context-menu.hidden {
    display: none;
}

.context-menu-item {
    padding: 10px 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 12px;
    transition: var(--transition);
    font-size: 14px;
}

.context-menu-item:hover {
    background: var(--bg-tertiary);
}

.context-menu-item.danger {
    color: var(--danger);
}

.context-menu-divider {
    height: 1px;
    background: var(--border);
    margin: 6px 0;
}

/* Toast */
#toast-container {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 5000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    pointer-events: none;
}

.toast {
    background: var(--bg-secondary);
    padding: 12px 20px;
    border-radius: 40px;
    border-left: 4px solid var(--primary);
    box-shadow: var(--shadow-lg);
    animation: slideUp 0.3s ease;
    font-size: 14px;
    pointer-events: auto;
}

.toast.error {
    border-left-color: var(--danger);
}

.toast.success {
    border-left-color: var(--success);
}

/* Loading Spinner */
.spinner {
    display: inline-block;
    width: 20px;
    height: 20px;
    border: 2px solid var(--border);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar {
        width: 100%;
        position: absolute;
        z-index: 100;
        transform: translateX(-100%);
        transition: transform 0.3s ease;
    }
    
    .sidebar.open {
        transform: translateX(0);
    }
    
    .message {
        max-width: 85%;
    }
    
    .wallpaper-options {
        grid-template-columns: 1fr;
    }
    
    .pin-btn {
        width: 60px;
        height: 60px;
        font-size: 24px;
    }
}