/* style.css — Nexus Messenger */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --bg2:       #161b26;
  --bg3:       #1e2535;
  --bg4:       #252d40;
  --border:    rgba(255,255,255,0.07);
  --accent:    #5b8aff;
  --accent2:   #a46bff;
  --accent-g:  linear-gradient(135deg, #5b8aff, #a46bff);
  --text:      #e8ecf4;
  --text2:     #8892aa;
  --text3:     #555f77;
  --bubble-me: #1e3a6e;
  --bubble-other: #1e2535;
  --danger:    #ff5b6b;
  --green:     #43d98e;
  --radius:    16px;
  --radius-sm: 8px;
  --font:      'DM Sans', sans-serif;
  --font-mono: 'Space Mono', monospace;
  --sidebar-w: 360px;
  --transition: 0.18s cubic-bezier(.4,0,.2,1);
}

html, body {
  height: 100%; height: calc(var(--vh, 1vh) * 100);
  font-family: var(--font);
  background: var(--bg); color: var(--text);
  font-size: 15px; line-height: 1.5;
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
/* ── Screens ─────────────────────────────────────────────────────────── */
.screen { display: none; width: 100%; height: 100vh; height: calc(var(--vh, 1vh) * 100); }
.screen.active { display: flex; }

/* ── Auth ─────────────────────────────────────────────────────────────── */
#auth-screen {
  align-items: center; justify-content: center;
  background: var(--bg); position: relative;
}
.auth-bg {
  position: absolute; inset: 0; z-index: 0;
  background: radial-gradient(ellipse 60% 50% at 30% 40%, rgba(91,138,255,0.12) 0%, transparent 70%),
              radial-gradient(ellipse 50% 40% at 80% 70%, rgba(164,107,255,0.1) 0%, transparent 70%);
}
.auth-card {
  position: relative; z-index: 1;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 24px; padding: 40px 36px;
  width: 100%; max-width: 420px;
  box-shadow: 0 32px 80px rgba(0,0,0,0.5);
}
.auth-logo {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 6px;
}
.auth-logo span {
  font-size: 26px; font-weight: 600; letter-spacing: -0.5px;
  background: var(--accent-g); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.auth-tagline { color: var(--text2); font-size: 13px; margin-bottom: 28px; }

.tab-bar {
  display: flex; background: var(--bg3); border-radius: var(--radius-sm);
  padding: 3px; margin-bottom: 24px;
}
.tab-btn {
  flex: 1; padding: 8px; border: none; background: transparent;
  color: var(--text2); border-radius: 6px; cursor: pointer; font-size: 14px;
  font-family: var(--font); transition: var(--transition);
}
.tab-btn.active {
  background: var(--bg4); color: var(--text); font-weight: 500;
}

.auth-form { display: none; flex-direction: column; gap: 16px; }
.auth-form.active { display: flex; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; color: var(--text2); font-weight: 500; }
.field input, .field select {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 11px 14px;
  color: var(--text); font-size: 15px; font-family: var(--font);
  outline: none; transition: border-color var(--transition);
}
.field input:focus, .field select:focus { border-color: var(--accent); }
.field select { cursor: pointer; }

.btn-primary {
  background: var(--accent-g); border: none; border-radius: var(--radius-sm);
  padding: 13px; color: white; font-size: 15px; font-weight: 600;
  cursor: pointer; font-family: var(--font); transition: opacity var(--transition);
}
.btn-primary:hover { opacity: 0.88; }
.btn-outline {
  background: transparent; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 9px 16px; color: var(--text2);
  font-size: 14px; cursor: pointer; font-family: var(--font);
  transition: border-color var(--transition);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent); }
.btn-danger {
  background: transparent; border: 1px solid rgba(255,91,107,0.3);
  border-radius: var(--radius-sm); padding: 11px; color: var(--danger);
  font-size: 14px; cursor: pointer; font-family: var(--font);
  transition: background var(--transition);
}
.btn-danger:hover { background: rgba(255,91,107,0.1); }

.auth-error {
  color: var(--danger); font-size: 13px; min-height: 18px; text-align: center;
}

/* ── App Layout ───────────────────────────────────────────────────────── */
#app-screen { flex-direction: column; }
.app-layout { display: flex; height: 100vh; height: calc(var(--vh, 1vh) * 100); width: 100%; }

/* ── Sidebar ──────────────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w); min-width: var(--sidebar-w);
  background: var(--bg2); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; height: 100%;
  transition: transform var(--transition);
}

.sidebar-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 16px 14px; border-bottom: 1px solid var(--border);
}
.sidebar-logo { display: flex; align-items: center; gap: 8px; }
.sidebar-title {
  font-size: 20px; font-weight: 700; letter-spacing: -0.3px;
  background: var(--accent-g); -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}
.sidebar-actions { display: flex; gap: 4px; }

.search-bar {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 12px; padding: 9px 14px; margin: 12px;
}
.search-bar svg { flex-shrink: 0; color: var(--text3); }
.search-bar input {
  background: transparent; border: none; outline: none;
  color: var(--text); font-size: 14px; font-family: var(--font); width: 100%;
}
.search-bar input::placeholder { color: var(--text3); }

.conv-list {
  flex: 1; overflow-y: auto; padding: 4px 0;
}
.conv-list::-webkit-scrollbar { width: 4px; }
.conv-list::-webkit-scrollbar-track { background: transparent; }
.conv-list::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }

.empty-convs {
  text-align: center; color: var(--text3); padding: 40px 20px;
  font-size: 14px; line-height: 1.7;
}

.conv-item {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; cursor: pointer; transition: background var(--transition);
  border-bottom: 1px solid var(--border); position: relative;
}
.conv-item:hover { background: var(--bg3); }
.conv-item.active { background: var(--bg3); }

.avatar {
  width: 46px; height: 46px; border-radius: 50%;
  background: var(--bg4); flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 18px; font-weight: 600; color: var(--text2);
  background: var(--accent-g); color: white;
  font-size: 16px; overflow: hidden; position: relative;
  user-select: none;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.large { width: 72px; height: 72px; font-size: 26px; }
.avatar.small { width: 34px; height: 34px; font-size: 12px; }
.online-dot {
  width: 10px; height: 10px; border-radius: 50%; background: var(--green);
  border: 2px solid var(--bg2); position: absolute; bottom: 1px; right: 1px;
}

.conv-info { flex: 1; min-width: 0; }
.conv-name {
  font-size: 15px; font-weight: 500; white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis; margin-bottom: 3px;
}
.conv-preview {
  font-size: 13px; color: var(--text2); white-space: nowrap;
  overflow: hidden; text-overflow: ellipsis;
}
.conv-meta {
  display: flex; flex-direction: column; align-items: flex-end; gap: 5px; flex-shrink: 0;
}
.conv-time { font-size: 12px; color: var(--text3); }
.unread-badge {
  background: var(--accent-g); color: white; border-radius: 50%;
  width: 20px; height: 20px; font-size: 11px; font-weight: 600;
  display: flex; align-items: center; justify-content: center;
}

.sidebar-me {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px; border-top: 1px solid var(--border);
  background: var(--bg2);
}
.sidebar-me .avatar { width: 38px; height: 38px; font-size: 14px; }
.me-info { display: flex; flex-direction: column; min-width: 0; }
.me-info span { font-size: 14px; font-weight: 500;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-username { font-size: 12px; color: var(--text3); }

/* ── Chat Panel ───────────────────────────────────────────────────────── */
.chat-panel {
  flex: 1; display: flex; flex-direction: column;
  background: var(--bg); position: relative; overflow: hidden;
}

.no-chat-selected {
  flex: 1; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 16px; color: var(--text3);
}
.no-chat-selected h2 { color: var(--text2); font-size: 22px; }
.no-chat-selected p { font-size: 14px; }
.no-chat-icon { margin-bottom: 8px; }

.active-chat { display: flex; flex-direction: column; height: 100%; }

/* Chat Header */
.chat-header {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 16px; border-bottom: 1px solid var(--border);
  background: var(--bg2); flex-shrink: 0;
}
.chat-header-avatar { width: 40px; height: 40px; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-size: 16px; font-weight: 600; display: block; }
.chat-header-status { font-size: 12px; color: var(--green); }
.chat-header-status.offline { color: var(--text3); }
.chat-header-actions { display: flex; gap: 4px; }
.back-btn { display: none; }

/* Messages */
.messages-area {
  flex: 1; overflow-y: auto; padding: 16px 0;
  background:
    radial-gradient(ellipse 80% 60% at 20% 20%, rgba(91,138,255,0.04) 0%, transparent 60%),
    var(--bg);
}
.messages-area::-webkit-scrollbar { width: 4px; }
.messages-area::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 2px; }

.messages-inner { display: flex; flex-direction: column; gap: 2px; padding: 0 16px 8px; }

.msg-group { margin-bottom: 8px; }
.date-separator {
  text-align: center; margin: 16px 0 8px;
  position: relative;
}
.date-separator span {
  background: var(--bg3); border: 1px solid var(--border);
  border-radius: 20px; padding: 4px 14px; font-size: 12px; color: var(--text3);
}

.msg-row {
  display: flex; align-items: flex-end; gap: 8px; margin: 1px 0;
  position: relative;
}
.msg-row.mine { flex-direction: row-reverse; }
.msg-row .avatar { width: 30px; height: 30px; font-size: 11px; flex-shrink: 0; }
.msg-row.mine .avatar { display: none; }

.bubble {
  max-width: 68%; padding: 9px 13px; border-radius: 18px;
  background: var(--bubble-other); position: relative;
  word-break: break-word; font-size: 15px;
  cursor: context-menu; user-select: text;
  box-shadow: 0 1px 4px rgba(0,0,0,0.25);
}
.msg-row.mine .bubble {
  background: var(--bubble-me); border-bottom-right-radius: 4px;
}
.msg-row:not(.mine) .bubble { border-bottom-left-radius: 4px; }

.bubble .reply-block {
  background: rgba(255,255,255,0.07); border-left: 3px solid var(--accent);
  border-radius: 8px; padding: 6px 10px; margin-bottom: 6px; font-size: 13px;
  cursor: pointer;
}
.bubble .reply-from { color: var(--accent); font-weight: 600; display: block; margin-bottom: 2px; }
.bubble .reply-quote { color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.bubble-media { max-width: 260px; }
.bubble-media img {
  width: 100%; border-radius: 12px; display: block; cursor: pointer;
  max-height: 320px; object-fit: cover;
}
.bubble-media video {
  width: 100%; border-radius: 12px; display: block; max-height: 320px;
}

.bubble-footer {
  display: flex; align-items: center; justify-content: flex-end;
  gap: 4px; margin-top: 4px;
}
.msg-time { font-size: 11px; color: var(--text3); }
.msg-ticks { color: var(--text3); font-size: 12px; }
.msg-ticks.read { color: var(--accent); }

.translate-text {
  margin-top: 6px; padding-top: 6px; border-top: 1px solid var(--border);
  font-size: 13px; color: var(--accent); font-style: italic;
}

/* Input Area */
.input-area {
  padding: 10px 12px; background: var(--bg2);
  border-top: 1px solid var(--border); flex-shrink: 0;
}
.reply-preview {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg3); border-radius: 10px; padding: 8px 12px;
  margin-bottom: 8px; border-left: 3px solid var(--accent);
}
.reply-preview-bar { width: 3px; align-self: stretch; background: var(--accent); border-radius: 2px; display: none; }
.reply-preview-content { flex: 1; min-width: 0; }
.reply-from { font-size: 12px; color: var(--accent); font-weight: 600; display: block; }
.reply-text { font-size: 13px; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; display: block; }

.input-row {
  display: flex; align-items: flex-end; gap: 8px;
}
.msg-input-wrap {
  flex: 1; background: var(--bg3); border: 1px solid var(--border);
  border-radius: 24px; padding: 10px 16px; min-height: 44px; max-height: 140px;
  overflow-y: auto; transition: border-color var(--transition);
}
.msg-input-wrap:focus-within { border-color: var(--accent); }
.msg-input {
  outline: none; color: var(--text); font-size: 15px; font-family: var(--font);
  line-height: 1.5; white-space: pre-wrap; word-break: break-word; min-height: 22px;
}
.msg-input:empty::before {
  content: attr(data-placeholder); color: var(--text3); pointer-events: none;
}

.icon-btn {
  background: transparent; border: none; color: var(--text2);
  cursor: pointer; padding: 8px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition);
  flex-shrink: 0; font-size: 20px;
}
.icon-btn:hover { background: var(--bg3); color: var(--text); }
.icon-btn.active { color: var(--accent); }

.emoji-btn { font-size: 22px; padding: 6px; }

.send-btn {
  background: var(--accent-g); border: none; border-radius: 50%;
  width: 44px; height: 44px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: white; flex-shrink: 0; transition: opacity var(--transition);
}
.send-btn:hover { opacity: 0.85; }

/* ── Modals ─────────────────────────────────────────────────────────────── */
.modal-overlay {
  display: none; position: fixed; inset: 0; z-index: 100;
  background: rgba(0,0,0,0.6); backdrop-filter: blur(4px);
  align-items: center; justify-content: center;
}
.modal-overlay.open { display: flex; }
.modal {
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 20px; padding: 24px; width: 90%; max-width: 400px;
  max-height: 80vh; overflow-y: auto; box-shadow: 0 24px 80px rgba(0,0,0,0.5);
  animation: slideUp 0.22s cubic-bezier(.4,0,.2,1);
}
@keyframes slideUp { from { transform: translateY(20px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 18px;
}
.modal-header h3 { font-size: 18px; font-weight: 600; }

.user-results { display: flex; flex-direction: column; gap: 4px; }
.user-result-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 10px; cursor: pointer;
  transition: background var(--transition);
}
.user-result-item:hover { background: var(--bg3); }
.user-result-item .info { flex: 1; }
.user-result-item .name { font-size: 15px; font-weight: 500; }
.user-result-item .username { font-size: 13px; color: var(--text3); }

.settings-body { display: flex; flex-direction: column; gap: 18px; }
.settings-avatar-row {
  display: flex; flex-direction: column; align-items: center; gap: 12px; padding: 8px 0;
}

/* ── Emoji Picker ────────────────────────────────────────────────────────── */
.emoji-picker {
  position: fixed; bottom: 70px; left: 16px; z-index: 50;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 16px; padding: 12px; width: 300px; max-height: 240px;
  overflow-y: auto; box-shadow: 0 8px 40px rgba(0,0,0,0.4);
  display: flex; flex-wrap: wrap; gap: 4px;
  animation: fadeIn 0.15s ease;
}
@keyframes fadeIn { from { opacity: 0; transform: scale(0.95); } to { opacity: 1; transform: scale(1); } }
.emoji-picker button {
  background: none; border: none; cursor: pointer; font-size: 22px;
  padding: 4px; border-radius: 8px; transition: background 0.1s;
}
.emoji-picker button:hover { background: var(--bg3); }

/* ── Context Menu ────────────────────────────────────────────────────────── */
.ctx-menu {
  position: fixed; z-index: 200; background: var(--bg2);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  box-shadow: 0 8px 30px rgba(0,0,0,0.4); min-width: 160px;
  animation: fadeIn 0.12s ease;
}
.ctx-item {
  display: block; width: 100%; background: none; border: none;
  color: var(--text); text-align: left; padding: 11px 16px;
  cursor: pointer; font-size: 14px; font-family: var(--font);
  transition: background var(--transition);
}
.ctx-item:hover { background: var(--bg3); }
.ctx-item.ctx-danger { color: var(--danger); }

/* ── Image Viewer ────────────────────────────────────────────────────────── */
.img-viewer {
  position: fixed; inset: 0; z-index: 300; background: rgba(0,0,0,0.9);
  display: flex; align-items: center; justify-content: center;
  animation: fadeIn 0.15s ease;
}
.img-viewer img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }
.img-close {
  position: absolute; top: 16px; right: 16px; color: white;
  background: rgba(255,255,255,0.1); font-size: 18px; width: 40px; height: 40px;
}

/* ── Toast ───────────────────────────────────────────────────────────────── */
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--bg3); border: 1px solid var(--border); border-radius: 30px;
  padding: 10px 22px; font-size: 14px; color: var(--text); pointer-events: none;
  opacity: 0; transition: all 0.2s ease; z-index: 999; white-space: nowrap;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ── Typing indicator ────────────────────────────────────────────────────── */
.typing-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.typing-dots { display: flex; gap: 4px; padding: 10px 14px;
  background: var(--bubble-other); border-radius: 18px; border-bottom-left-radius: 4px; }
.typing-dots span {
  width: 7px; height: 7px; border-radius: 50%; background: var(--text3);
  animation: bounce 1.2s infinite; display: block;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }

/* ── Translate active indicator ─────────────────────────────────────────── */
#translate-toggle-btn.active { color: var(--accent); }

/* ── Responsive ──────────────────────────────────────────────────────────── */
@media (max-width: 700px) {
  :root { --sidebar-w: 100%; }
  .sidebar { position: absolute; left: 0; top: 0; bottom: 0; z-index: 10; width: 100%; min-width: 100%; }
  .sidebar.hidden { transform: translateX(-100%); }
  .chat-panel { width: 100%; }
  .back-btn { display: flex !important; }
  .no-chat-selected { display: none; }
  .input-area { padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .active-chat { height: calc(var(--vh, 1vh) * 100); }
}

/* Scrollbar global */
* { scrollbar-width: thin; scrollbar-color: var(--bg4) transparent; }
