/* ============================================================
   CHAT APP — Modern Dark Theme with Glassmorphism
   ============================================================ */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap');

/* ---------- CSS Variables ---------- */
:root {
  --bg-dark: #0d0d1a;
  --bg-panel: #12121f;
  --bg-card: rgba(255, 255, 255, 0.04);
  --bg-card-hover: rgba(255, 255, 255, 0.08);
  --glass: rgba(255, 255, 255, 0.06);
  --glass-border: rgba(255, 255, 255, 0.10);
  --accent: #7c3aed;
  --accent-2: #4f46e5;
  --accent-light: #a78bfa;
  --msg-sent: #4f46e5;
  --msg-recv: rgba(255, 255, 255, 0.07);
  --text-primary: #f1f0ff;
  --text-secondary: #9ca3af;
  --text-muted: #6b7280;
  --danger: #ef4444;
  --success: #22c55e;
  --border: rgba(255, 255, 255, 0.08);
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
  --radius: 16px;
  --radius-sm: 10px;
  --radius-xs: 6px;
  --transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ---------- Reset ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-dark);
  color: var(--text-primary);
  height: 100%;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Scrollbar ---------- */
::-webkit-scrollbar {
  width: 4px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--glass-border);
  border-radius: 2px;
}

/* ============================================================
   AUTH SCREEN
   ============================================================ */
#auth-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: radial-gradient(ellipse at 20% 50%, rgba(124, 58, 237, 0.18) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 20%, rgba(79, 70, 229, 0.14) 0%, transparent 55%),
    var(--bg-dark);
  padding: 1rem;
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--glass);
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  border: 1px solid var(--glass-border);
  border-radius: 24px;
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow);
}

.auth-logo {
  text-align: center;
  margin-bottom: 2rem;
}

.auth-logo .logo-icon {
  width: 60px;
  height: 60px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border-radius: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  margin-bottom: 0.75rem;
  box-shadow: 0 8px 24px rgba(124, 58, 237, 0.4);
}

.auth-logo h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.auth-logo p {
  font-size: 0.85rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

.auth-tabs {
  display: flex;
  background: rgba(0, 0, 0, 0.3);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 1.75rem;
}

.auth-tab {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-secondary);
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.6rem;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: var(--transition);
}

.auth-tab.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.35);
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
  letter-spacing: 0.03em;
}

.form-group input {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.7rem 1rem;
  transition: var(--transition);
  outline: none;
}

.form-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(124, 58, 237, 0.2);
}

.form-group input::placeholder {
  color: var(--text-muted);
}

.btn-primary {
  width: 100%;
  padding: 0.8rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: inherit;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  margin-top: 0.5rem;
  box-shadow: 0 4px 16px rgba(124, 58, 237, 0.35);
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(124, 58, 237, 0.5);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-primary:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.auth-error {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
  border-radius: var(--radius-xs);
  padding: 0.6rem 0.9rem;
  font-size: 0.82rem;
  margin-top: 0.75rem;
  display: none;
}

.auth-error.show {
  display: block;
}

/* ============================================================
   MAIN APP LAYOUT
   ============================================================ */
#app-screen {
  display: flex;
  height: 100vh;
  height: 100dvh;
  /* accounts for mobile address bar */
  overflow: hidden;
}

/* ---- Sidebar ---- */
#sidebar {
  width: 340px;
  min-width: 280px;
  background: var(--bg-panel);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: relative;
  transition: var(--transition);
}

.sidebar-header {
  padding: 1.25rem 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.sidebar-header .app-title {
  flex: 1;
  font-size: 1.15rem;
  font-weight: 700;
  background: linear-gradient(90deg, var(--accent-light), #818cf8);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

.icon-btn {
  width: 38px;
  height: 38px;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 1rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.icon-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Search bar */
.search-bar {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.search-input-wrap {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0 0.75rem;
  gap: 0.5rem;
}

.search-input-wrap .search-icon {
  color: var(--text-muted);
  font-size: 0.9rem;
}

.search-input-wrap input {
  flex: 1;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.88rem;
  padding: 0.6rem 0;
}

.search-input-wrap input::placeholder {
  color: var(--text-muted);
}

/* Search results */
#search-results {
  position: absolute;
  top: 130px;
  left: 0;
  right: 0;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  z-index: 50;
  display: none;
  max-height: 300px;
  overflow-y: auto;
}

#search-results.show {
  display: block;
}

.search-result-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  cursor: pointer;
  transition: var(--transition);
  border-bottom: 1px solid var(--border);
}

.search-result-item:hover {
  background: var(--bg-card-hover);
}

.search-result-item .item-name {
  flex: 1;
  font-size: 0.9rem;
  font-weight: 500;
}

.search-result-item .item-action {
  font-size: 0.75rem;
}

/* Tabs */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-tab {
  flex: 1;
  padding: 0.7rem;
  text-align: center;
  font-size: 0.82rem;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: var(--transition);
  position: relative;
}

.sidebar-tab.active {
  color: var(--accent-light);
  border-bottom-color: var(--accent);
}

.tab-badge {
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 5px;
  position: absolute;
  top: 6px;
  right: 12px;
  display: none;
}

.tab-badge.show {
  display: inline;
}

/* Friend list */
.friend-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem 0;
}

.friend-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

.friend-item:hover {
  background: var(--bg-card-hover);
}

.friend-item.active {
  background: rgba(124, 58, 237, 0.15);
}

.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  font-weight: 600;
  flex-shrink: 0;
  position: relative;
  overflow: hidden;
  text-transform: uppercase;
  color: #fff;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar.small {
  width: 34px;
  height: 34px;
  font-size: 0.85rem;
}

.online-dot {
  position: absolute;
  bottom: 1px;
  right: 1px;
  width: 11px;
  height: 11px;
  background: var(--success);
  border: 2px solid var(--bg-panel);
  border-radius: 50%;
}

.friend-info {
  flex: 1;
  min-width: 0;
}

.friend-name {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--text-primary);
}

.friend-status {
  font-size: 0.78rem;
  color: var(--text-secondary);
  margin-top: 2px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 2px 7px;
  min-width: 20px;
  text-align: center;
}

/* Pending requests */
.request-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.8rem 1rem;
  border-bottom: 1px solid var(--border);
}

.request-info {
  flex: 1;
}

.request-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.request-actions {
  display: flex;
  gap: 0.4rem;
}

.btn-accept {
  background: rgba(34, 197, 94, 0.15);
  border: 1px solid rgba(34, 197, 94, 0.3);
  color: var(--success);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.btn-accept:hover {
  background: rgba(34, 197, 94, 0.25);
}

.btn-reject {
  background: rgba(239, 68, 68, 0.15);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: var(--danger);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3rem 0.7rem;
  border-radius: var(--radius-xs);
  cursor: pointer;
  transition: var(--transition);
  font-family: inherit;
}

.btn-reject:hover {
  background: rgba(239, 68, 68, 0.25);
}

.empty-state {
  text-align: center;
  padding: 3rem 1.5rem;
  color: var(--text-muted);
  font-size: 0.88rem;
}

.empty-state .icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
}

/* Sidebar footer / user bar */
.sidebar-footer {
  padding: 0.9rem 1rem;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-shrink: 0;
}

.user-info {
  flex: 1;
  min-width: 0;
}

.user-name {
  font-size: 0.9rem;
  font-weight: 600;
}

.user-sub {
  font-size: 0.75rem;
  color: var(--success);
}

/* ============================================================
   CHAT PANEL
   ============================================================ */
#chat-panel {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  position: relative;
  background: var(--bg-dark);
  min-width: 0;
  overflow: hidden;
}

/* messages fill remaining space, input stays at bottom */
#messages-wrapper {
  flex: 1 1 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}

#chat-input-area {
  flex-shrink: 0;
  width: 100%;
}

/* ============================================================
   MOBILE RESPONSIVE LAYOUT  (≤ 768px)
   ============================================================ */
@media (max-width: 768px) {

  /* Use JS-set --vh custom property as fallback for older Androids */
  #app-screen {
    position: relative;
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
  }

  /* Sidebar fills full screen on mobile */
  #sidebar {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 10;
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    transform: translateX(0);
    overflow-y: auto;
  }

  /* Sidebar hidden = slide out to the left */
  #sidebar.hidden {
    display: flex !important;
    /* override .hidden's display:none */
    transform: translateX(-100%);
  }

  /* Chat panel fills full screen, keyboard-safe */
  #chat-panel {
    position: absolute;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    height: 100dvh;
    z-index: 5;
    transform: translateX(100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  /* When chat is active, slide it in */
  #chat-panel.active {
    transform: translateX(0);
  }

  /* Messages scrollable area — takes all remaining space */
  #messages-wrapper {
    flex: 1 1 0;
    min-height: 0;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 0.75rem;
  }

  /* Input BAR — always at the bottom, never hidden */
  #chat-input-area {
    flex-shrink: 0;
    position: relative;
    bottom: auto;
    left: auto;
    right: auto;
    padding: 0.6rem 0.75rem;
    padding-bottom: max(0.6rem, env(safe-area-inset-bottom));
    background: var(--bg-panel);
    border-top: 1px solid var(--border);
    z-index: 20;
  }

  /* Fix message bubbles max-width on mobile */
  .msg-bubble {
    max-width: 85%;
  }

  /* Fix file previews */
  .msg-media-wrap,
  .msg-file {
    max-width: 220px;
  }

  /* Status bar */
  .status-avatars {
    padding-bottom: 0.5rem;
  }

  /* Status composer full-width on mobile */
  .status-composer-box {
    max-width: 100%;
    border-radius: 18px 18px 0 0;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
  }

  .status-composer-overlay {
    align-items: flex-end;
    padding: 0;
  }
}


/* Welcome state */
#chat-welcome {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  text-align: center;
}

.welcome-icon {
  font-size: 4rem;
  margin-bottom: 1.25rem;
  animation: float 3s ease-in-out infinite;
}

@keyframes float {

  0%,
  100% {
    transform: translateY(0);
  }

  50% {
    transform: translateY(-10px);
  }
}

.welcome-title {
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.welcome-sub {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

/* Chat header */
#chat-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.9rem 1rem;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-info {
  flex: 1;
}

.chat-header-name {
  font-size: 1rem;
  font-weight: 600;
}

.chat-header-status {
  font-size: 0.78rem;
  color: var(--text-secondary);
}

.chat-header-status.online {
  color: var(--success);
}

/* back button — visible on all screen sizes */
.back-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-primary);
  cursor: pointer;
  font-size: 1rem;
}

/* Messages area */
#messages-wrapper {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.msg-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  animation: fadeUp 0.2s ease both;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(8px);
  }

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.msg-row.sent {
  flex-direction: row-reverse;
}



.msg-bubble {
  max-width: 72%;
  padding: 0.6rem 0.9rem;
  border-radius: 18px;
  position: relative;
  font-size: 0.9rem;
  line-height: 1.5;
  word-break: break-word;
}

.msg-row.sent .msg-bubble {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border-bottom-right-radius: 4px;
}

.msg-row.recv .msg-bubble {
  background: var(--msg-recv);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-bottom-left-radius: 4px;
}

.msg-time {
  font-size: 0.66rem;
  color: rgba(255, 255, 255, 0.55);
  text-align: right;
  margin-top: 3px;
}

.msg-row.recv .msg-time {
  color: var(--text-muted);
}

/* File messages */
.msg-file {
  max-width: 260px;
  cursor: pointer;
}

.msg-file img {
  width: 100%;
  border-radius: 10px;
  display: block;
  max-height: 200px;
  object-fit: cover;
}

.msg-file video {
  width: 100%;
  border-radius: 10px;
  display: block;
  max-height: 200px;
}

.msg-file-name {
  font-size: 0.78rem;
  margin-top: 4px;
  opacity: 0.8;
}

/* Date divider */
.date-divider {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin: 0.5rem 0;
  position: relative;
}

.date-divider::before,
.date-divider::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--border);
}

.date-divider::before {
  left: 0;
}

.date-divider::after {
  right: 0;
}

/* Typing indicator */
.typing-indicator {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: var(--msg-recv);
  border: 1px solid var(--border);
  border-radius: 18px;
  border-bottom-left-radius: 4px;
  width: fit-content;
}

.typing-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: blink 1.2s infinite;
}

.typing-dot:nth-child(2) {
  animation-delay: 0.2s;
}

.typing-dot:nth-child(3) {
  animation-delay: 0.4s;
}

@keyframes blink {

  0%,
  80%,
  100% {
    opacity: 0.3;
  }

  40% {
    opacity: 1;
  }
}

/* ---- Chat Input ---- */
#chat-input-area {
  padding: 0.75rem 1rem;
  background: var(--bg-panel);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* File preview */
#file-preview {
  display: none;
  align-items: center;
  gap: 0.6rem;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.6rem;
}

#file-preview.show {
  display: flex;
}

#file-preview .preview-thumb {
  width: 40px;
  height: 40px;
  border-radius: 6px;
  object-fit: cover;
  background: var(--glass);
}

#file-preview .preview-name {
  flex: 1;
  font-size: 0.82rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#file-preview .preview-remove {
  cursor: pointer;
  color: var(--danger);
  padding: 0.2rem;
  font-size: 1rem;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}

#msg-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border);
  border-radius: 24px;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.65rem 1rem;
  outline: none;
  resize: none;
  max-height: 120px;
  transition: var(--transition);
  line-height: 1.4;
}

#msg-input:focus {
  border-color: var(--accent);
}

#msg-input::placeholder {
  color: var(--text-muted);
}

.send-btn {
  width: 44px;
  height: 44px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: var(--transition);
  flex-shrink: 0;
  box-shadow: 0 4px 12px rgba(124, 58, 237, 0.35);
}

.send-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 16px rgba(124, 58, 237, 0.5);
}

.attach-btn {
  width: 38px;
  height: 38px;
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: var(--text-secondary);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  transition: var(--transition);
  flex-shrink: 0;
}

.attach-btn:hover {
  background: var(--bg-card-hover);
  color: var(--text-primary);
}

/* Emoji picker */
#emoji-picker {
  position: absolute;
  bottom: 70px;
  right: 60px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem;
  display: none;
  flex-wrap: wrap;
  gap: 4px;
  width: 280px;
  max-height: 180px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  z-index: 100;
}

#emoji-picker.show {
  display: flex;
}

.emoji-btn {
  font-size: 1.4rem;
  cursor: pointer;
  padding: 3px;
  border-radius: 6px;
  transition: background 0.15s;
  background: none;
  border: none;
}

.emoji-btn:hover {
  background: var(--bg-card-hover);
}

/* ============================================================
   ENCRYPTION BADGE
   ============================================================ */
.e2e-badge {
  text-align: center;
  font-size: 0.73rem;
  color: var(--text-muted);
  padding: 0.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}

.e2e-badge .lock-icon {
  color: var(--success);
}

/* ============================================================
   TOAST NOTIFICATIONS
   ============================================================ */
#toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  font-size: 0.85rem;
  box-shadow: var(--shadow);
  min-width: 220px;
  animation: slideIn 0.3s ease, fadeOut 0.3s ease 2.7s forwards;
  pointer-events: auto;
}

.toast.success {
  border-left: 3px solid var(--success);
}

.toast.error {
  border-left: 3px solid var(--danger);
}

.toast.info {
  border-left: 3px solid var(--accent);
}

@keyframes slideIn {
  from {
    transform: translateX(100%);
    opacity: 0;
  }

  to {
    transform: translateX(0);
    opacity: 1;
  }
}

@keyframes fadeOut {
  from {
    opacity: 1;
  }

  to {
    opacity: 0;
  }
}

/* ============================================================
   LOADING SPINNER
   ============================================================ */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--accent-light);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  display: inline-block;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ============================================================
   LIGHTBOX / MEDIA VIEWER
   ============================================================ */
#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 9998;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#lightbox.show {
  display: flex;
}

#lightbox img,
#lightbox video {
  max-width: 95%;
  max-height: 90vh;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

#lightbox-close {
  position: absolute;
  top: 1rem;
  right: 1rem;
  background: rgba(0, 0, 0, 0.5);
  border: 1px solid var(--border);
  border-radius: 50%;
  color: #fff;
  cursor: pointer;
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ============================================================
   MOBILE RESPONSIVE
   ============================================================ */
@media (max-width: 700px) {
  #app-screen {
    position: relative;
  }

  #sidebar {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    width: 100%;
    z-index: 200;
    transform: translateX(0);
    transition: transform 0.3s ease;
  }

  #sidebar.hidden {
    transform: translateX(-100%);
  }

  #chat-panel {
    position: fixed;
    left: 0;
    top: 0;
    bottom: 0;
    right: 0;
    z-index: 100;
    transform: translateX(100%);
    transition: transform 0.3s ease;
    display: flex;
  }

  #chat-panel.active {
    transform: translateX(0);
  }

  /* back-btn is always flex; on mobile sidebar/panel toggle handles navigation */
  #emoji-picker {
    right: 10px;
    width: 250px;
  }
}

/* -------- Settings dropdown -------- */
.dropdown {
  position: relative;
}

.dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  left: auto;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 160px;
  box-shadow: var(--shadow);
  z-index: 300;
  overflow: hidden;
}

.dropdown-menu.show {
  display: block;
}

.dropdown-item {
  padding: 0.7rem 1rem;
  font-size: 0.87rem;
  color: var(--text-primary);
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  transition: background 0.15s;
}

.dropdown-item:hover {
  background: var(--bg-card-hover);
}

.dropdown-item.danger {
  color: var(--danger);
}

/* -------- Utility -------- */
.hidden {
  display: none !important;
}

.text-muted {
  color: var(--text-muted);
}

.fw600 {
  font-weight: 600;
}

/* ============================================================
   SETTINGS MODAL
   ============================================================ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

.modal-card {
  width: 100%;
  max-width: 440px;
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 20px;
  box-shadow: 0 24px 64px rgba(0, 0, 0, 0.6);
  overflow: hidden;
  animation: slideUp 0.25s cubic-bezier(0.34, 1.56, 0.64, 1);
}

@keyframes slideUp {
  from {
    transform: translateY(24px);
    opacity: 0;
  }

  to {
    transform: translateY(0);
    opacity: 1;
  }
}

.modal-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--glass);
}

.modal-header h3 {
  flex: 1;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.modal-close {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: var(--radius-xs);
  color: var(--text-secondary);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-size: 0.9rem;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--bg-card-hover);
  color: var(--danger);
}

.modal-body {
  padding: 1.25rem 1.5rem;
  overflow-y: auto;
  max-height: 70vh;
}

.settings-section {
  padding: 1.1rem 0;
  border-bottom: 1px solid var(--border);
}

.settings-section:last-child {
  border-bottom: none;
}

.settings-section-title {
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--accent-light);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-bottom: 0.85rem;
}

/* Avatar upload */
.avatar-upload-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.6rem;
}

.avatar-preview-wrap {
  position: relative;
  cursor: pointer;
}

.settings-avatar {
  width: 88px;
  height: 88px;
  font-size: 2rem;
  border: 3px solid var(--accent);
  transition: var(--transition);
}

.settings-avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 50%;
}

.avatar-overlay {
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.52);
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.2s;
  cursor: pointer;
  color: #fff;
  font-size: 1.1rem;
}

.avatar-preview-wrap:hover .avatar-overlay {
  opacity: 1;
}

.settings-hint {
  font-size: 0.74rem;
  color: var(--text-muted);
}

/* Settings save button */
.btn-settings-save {
  padding: 0.55rem 1.2rem;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  border: none;
  border-radius: var(--radius-sm);
  color: #fff;
  font-family: inherit;
  font-size: 0.87rem;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
  display: flex;
  align-items: center;
  gap: 0.4rem;
  margin-top: 0.6rem;
}

.btn-settings-save:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 14px rgba(124, 58, 237, 0.4);
}

.btn-settings-save:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

/* Settings status message */
.settings-msg {
  margin-top: 0.5rem;
  font-size: 0.82rem;
  padding: 0.4rem 0.7rem;
  border-radius: var(--radius-xs);
}

.settings-msg.success {
  background: rgba(34, 197, 94, 0.12);
  color: var(--success);
  border: 1px solid rgba(34, 197, 94, 0.3);
}

.settings-msg.error {
  background: rgba(239, 68, 68, 0.12);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.3);
}

/* ── Password show/hide toggle ── */
.pw-wrap {
  position: relative;
  display: flex;
  align-items: center;
}

.pw-wrap input {
  width: 100%;
  padding-right: 2.6rem !important;
  /* room for eye icon */
}

.pw-toggle {
  position: absolute;
  right: 0.65rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0;
  font-size: 0.95rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s;
  line-height: 1;
}

.pw-toggle:hover {
  color: var(--accent-light);
}

.pw-toggle.visible {
  color: var(--accent-light);
}

/* ── Friend item context menu (Unfriend / Block) ── */
.friend-item {
  position: relative;
}

/* ensure stacking context */

.friend-ctx-btn {
  position: absolute;
  right: 0.55rem;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  width: 26px;
  height: 26px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  font-size: 0.85rem;
  opacity: 0;
  transition: opacity 0.15s, background 0.15s;
  z-index: 2;
}

.friend-item:hover .friend-ctx-btn,
.friend-item.active .friend-ctx-btn {
  opacity: 1;
}

.friend-ctx-btn:hover {
  background: var(--glass);
  color: var(--text-primary);
}

.friend-ctx-menu {
  display: none;
  position: absolute;
  right: 0.4rem;
  top: calc(100% - 4px);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
  z-index: 100;
  min-width: 140px;
  overflow: hidden;
}

.friend-ctx-menu.show {
  display: block;
  animation: slideUp 0.15s ease;
}

.ctx-item {
  padding: 0.6rem 0.9rem;
  font-size: 0.83rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-primary);
  transition: background 0.12s;
}

.ctx-item:hover {
  background: var(--bg-card-hover);
}

.ctx-item.danger {
  color: var(--danger);
}

.ctx-item.danger:hover {
  background: rgba(239, 68, 68, 0.1);
}

/* ============================================================
   REACTIONS
   ============================================================ */
.msg-bubble {
  position: relative;
}

/* Quick emoji bar — appears on bubble hover */
.quick-reactions {
  display: none;
  position: absolute;
  bottom: 100%;
  /* flush with bubble top — no gap */
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 3px 6px;
  padding-bottom: 8px;
  /* extends hover zone downward to bridge gap */
  gap: 2px;
  z-index: 20;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.45);
  white-space: nowrap;
}

/* Override left/right alignment — centre is fine for both sides */
.sent .quick-reactions,
.recv .quick-reactions {
  left: 50%;
  right: auto;
}

.msg-bubble:hover .quick-reactions,
.quick-reactions:hover {
  display: flex;
}

/* keep showing when moving into it */

.qr-btn {
  background: none;
  border: none;
  cursor: pointer;
  font-size: 1.1rem;
  padding: 2px 3px;
  border-radius: 50%;
  transition: transform 0.15s;
  line-height: 1;
}

.qr-btn:hover {
  transform: scale(1.3);
}

.reply-qr-btn {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Reaction pills (below bubble) */
.reaction-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 5px;
}

.reaction-pill {
  background: var(--glass);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 8px;
  font-size: 0.82rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
  transition: var(--transition);
}

.reaction-pill.mine {
  background: rgba(124, 58, 237, 0.2);
  border-color: var(--accent);
}

.reaction-pill:hover {
  transform: scale(1.08);
}

/* ============================================================
   REPLY QUOTE (inside message bubble)
   ============================================================ */
.reply-quote {
  background: rgba(255, 255, 255, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 5px 9px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.15s;
}

.reply-quote:hover {
  background: rgba(255, 255, 255, 0.1);
}

.reply-quote-name {
  font-size: 0.73rem;
  font-weight: 700;
  color: var(--accent-light);
  margin-bottom: 2px;
}

.reply-quote-text {
  font-size: 0.8rem;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Reply input bar (above textarea) */
#reply-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--glass);
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  padding: 6px 12px;
  gap: 8px;
}

#reply-bar-content {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

.reply-bar-text {
  flex: 1;
  min-width: 0;
}

.reply-bar-name {
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--accent-light);
}

.reply-bar-preview {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#reply-cancel {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  padding: 0 4px;
  flex-shrink: 0;
}

#reply-cancel:hover {
  color: var(--danger);
}

/* ============================================================
   VOICE MESSAGE
   ============================================================ */
#voice-indicator {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(239, 68, 68, 0.08);
  border-top: 1px solid rgba(239, 68, 68, 0.2);
  font-size: 0.85rem;
}

.voice-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #ef4444;
  animation: pulseDot 1s infinite;
  flex-shrink: 0;
}

@keyframes pulseDot {

  0%,
  100% {
    opacity: 1;
    transform: scale(1);
  }

  50% {
    opacity: 0.4;
    transform: scale(0.7);
  }
}

#voice-timer {
  font-weight: 700;
  color: #ef4444;
  min-width: 32px;
}

#voice-cancel {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 0.9rem;
  margin-left: auto;
}

#voice-cancel:hover {
  color: var(--danger);
}

/* Custom WhatsApp-style audio player (no download) */
.msg-audio {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 200px;
  max-width: 260px;
  padding: 4px 0;
  user-select: none;
}

.ap-play {
  width: 36px;
  height: 36px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.9rem;
  transition: background 0.15s, transform 0.1s;
}

.ap-play:hover {
  background: var(--accent-light);
  transform: scale(1.05);
}

.ap-play:active {
  transform: scale(0.95);
}

.ap-track {
  display: flex;
  flex-direction: column;
  flex: 1;
  gap: 3px;
}

.ap-bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.18);
  border-radius: 2px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.ap-fill {
  height: 100%;
  background: var(--accent-light);
  border-radius: 2px;
  width: 0;
  transition: width 0.1s linear;
}

.ap-time {
  font-size: 0.72rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}


/* Message highlight when jumping to quoted original */
.msg-row.highlight .msg-bubble {
  animation: flashHighlight 1.2s ease;
}

@keyframes flashHighlight {

  0%,
  100% {
    box-shadow: none;
  }

  30% {
    box-shadow: 0 0 0 3px var(--accent);
  }
}

/* ============================================================
   MESSAGE SEEN RECEIPTS (tick marks)
   ============================================================ */
.msg-meta {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
}

.msg-time {
  font-size: 0.68rem;
  color: rgba(255, 255, 255, 0.45);
  line-height: 1;
  white-space: nowrap;
}

.msg-tick {
  display: inline-flex;
  align-items: center;
  line-height: 1;
  flex-shrink: 0;
}

.msg-tick svg {
  display: block;
}

/* Blue double tick when seen */
.msg-tick.seen svg path {
  stroke: #60a5fa;
}

/* recv bubbles: time left-aligned, no tick */
.recv .msg-meta {
  justify-content: flex-start;
}

/* ============================================================
   MEDIA WRAPPER + DOWNLOAD BUTTON ON RECEIVED MEDIA
   ============================================================ */
.msg-media-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-width: 260px;
}

.msg-download-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 6px 14px;
  background: rgba(124, 58, 237, 0.18);
  border: 1px solid rgba(124, 58, 237, 0.35);
  border-radius: 20px;
  color: var(--accent-light);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: background 0.2s ease, transform 0.15s ease;
  width: fit-content;
  align-self: flex-start;
  letter-spacing: 0.02em;
}

.msg-download-btn:hover,
.msg-download-btn:active {
  background: rgba(124, 58, 237, 0.35);
  transform: scale(1.03);
  color: #fff;
}

/* ============================================================
   PRIVACY BLUR TOGGLE BUTTON
   ============================================================ */
.blur-btn {
  color: var(--text-muted);
  font-size: 0.95rem;
}

.blur-btn.active {
  color: var(--accent-light);
  background: rgba(124, 58, 237, 0.2);
  border-color: rgba(124, 58, 237, 0.4);
  box-shadow: 0 0 10px rgba(124, 58, 237, 0.3);
}

/* ============================================================
   BLURRED MESSAGES (Privacy Mode)
   ============================================================ */
.msg-row {
  transition: filter 0.3s ease;
}

.msg-row.msg-blurred {
  filter: blur(7px);
  user-select: none;
  pointer-events: none;
}