/* ── Reset & tokens ────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:       #0d0e1a;
  --bg2:      #13152a;
  --bg3:      #1b1e36;
  --bg4:      #222645;
  --border:   rgba(255,255,255,0.07);
  --text:     #eef0f8;
  --text2:    #8890b8;
  --text3:    #4a5070;
  --accent:   #4f6ef7;
  --accent2:  #7b93ff;
  --online:   #4ade80;
  --danger:   #f87171;
  --danger-bg:rgba(248,113,113,0.12);
  --radius:   14px;
  --shadow:   0 8px 32px rgba(0,0,0,0.45);
}
[data-theme="light"] {
  --bg:       #f0f2fc;
  --bg2:      #ffffff;
  --bg3:      #f5f6ff;
  --bg4:      #e8eaf8;
  --border:   rgba(0,0,0,0.07);
  --text:     #0d0e1e;
  --text2:    #5560a0;
  --text3:    #a0a8c8;
  --accent:   #4f6ef7;
  --accent2:  #3355e0;
  --online:   #22c55e;
  --danger:   #ef4444;
  --danger-bg:rgba(239,68,68,0.08);
  --shadow:   0 4px 24px rgba(0,0,0,0.10);
}

html, body { height: 100%; overflow: hidden; }
/* Prevent text selection globally but allow paste */
.bubble { -webkit-user-select: none; user-select: none; }
.messages-area { -webkit-user-select: none; user-select: none; }
body {
  font-family: 'Outfit', -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 4px; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea { font-family: inherit; }
a { text-decoration: none; color: inherit; }

/* ── App shell (desktop: sidebar + main) ──────── */
.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ── Sidebar ───────────────────────────────────── */
.sidebar {
  width: 320px;
  min-width: 320px;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.3s;
}

.sidebar-top {
  padding: 16px 16px 6px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.brand-name {
  font-size: 22px;
  font-weight: 900;
  letter-spacing: -0.8px;
  color: var(--text);
  background: linear-gradient(135deg, var(--text) 30%, var(--accent2) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.brand-name em {
  font-style: normal;
  -webkit-text-fill-color: var(--accent2);
}

.sidebar-search {
  position: relative;
  display: none; /* toggled by JS */
}
.sidebar-search.open { display: block; }
.sidebar-search input {
  width: 100%;
  padding: 9px 14px 9px 38px;
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: 10px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-size: 16px;
}
.sidebar-search input:focus { border-color: var(--accent); }
.sidebar-search .search-ico {
  position: absolute;
  left: 12px; top: 50%;
  transform: translateY(-50%);
  color: var(--text3);
  pointer-events: none;
  font-size: 14px;
}

.contacts-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
}

.contact-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 12px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  position: relative;
}
.contact-card:hover { background: var(--bg3); }
.contact-card.active { background: rgba(79,110,247,0.12); border-left: 2px solid var(--accent); }

.contact-avatar {
  position: relative;
  flex-shrink: 0;
}
.contact-avatar img, .avatar-circle {
  width: 46px; height: 46px;
  border-radius: 14px;
  object-fit: cover;
  display: block;
}
.avatar-circle {
  background: rgba(79,110,247,0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
}
.online-dot {
  position: absolute;
  bottom: -1px; right: -1px;
  width: 11px; height: 11px;
  border-radius: 50%;
  border: 2px solid var(--bg2);
  background: var(--text3);
  transition: background 0.3s;
}
.online-dot.on { background: var(--online); box-shadow: 0 0 5px rgba(74,222,128,0.6); }

.contact-info { flex: 1; min-width: 0; }
.contact-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-last { font-size: 12px; color: var(--text2); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-typing { font-size: 12px; color: var(--accent); margin-top: 2px; font-style: italic; }

.unread-badge {
  min-width: 20px; height: 20px;
  background: var(--danger);
  border-radius: 10px;
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

.sidebar-bottom {
  padding: 10px 12px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.user-chip {
  display: flex;
  align-items: center;
  gap: 9px;
  flex: 0 1 auto; /* shrink to content, don't force full width */
  min-width: 0;
  max-width: 180px;
  padding: 7px 9px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.15s;
}
.user-chip:hover { background: var(--bg3); }
.user-chip img, .user-chip .avatar-circle {
  width: 34px; height: 34px;
  border-radius: 10px;
  flex-shrink: 0;
}
.user-chip-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.ico-btn {
  width: 36px; height: 36px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 17px;
  background: var(--bg3);
  border: 1px solid var(--border);
  transition: all 0.15s;
  position: relative;
  flex-shrink: 0;
}
.ico-btn:hover { background: var(--bg4); }
.ico-btn .badge {
  position: absolute;
  top: -4px; right: -4px;
  min-width: 16px; height: 16px;
  background: var(--danger);
  border-radius: 8px;
  font-size: 9px; font-weight: 700;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg2);
}

/* ── Main content area ────────────────────────── */
.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}

.empty-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text3);
  gap: 12px;
}
.empty-main .empty-icon { font-size: 64px; opacity: 0.15; }
.empty-main .empty-title { font-size: 18px; font-weight: 600; color: var(--text2); }
.empty-main .empty-sub { font-size: 13px; max-width: 240px; text-align: center; line-height: 1.7; }
.empty-main .e2e { font-size: 11px; color: var(--online); background: rgba(74,222,128,0.1); padding: 4px 10px; border-radius: 20px; border: 1px solid rgba(74,222,128,0.2); }

/* ── Chat page ─────────────────────────────────── */
.chat-page {
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 10;
}
.chat-header .back-btn { display: none; }
.chat-header-info { flex: 1; min-width: 0; }
.chat-header-name { font-weight: 700; font-size: 15px; }
.chat-header-status { font-size: 12px; color: var(--text2); margin-top: 2px; display: flex; align-items: center; gap: 5px; }
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--text3); }
.status-dot.on { background: var(--online); }
.online-text { color: var(--online); }

.messages-area {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.day-divider {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--text3);
  padding: 8px 0;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.day-divider::before, .day-divider::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.msg-row { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 2px; animation: msgPop 0.2s ease; }
.msg-row.out { flex-direction: row-reverse; }
@keyframes msgPop { from { opacity:0; transform:translateY(6px); } to { opacity:1; transform:translateY(0); } }

.msg-avatar { width: 28px; height: 28px; border-radius: 8px; object-fit: cover; flex-shrink: 0; }

.bubble {
  max-width: 65%;
  padding: 7px 11px 6px 11px;
  border-radius: 14px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
  position: relative;
  display: block;          /* must be block for float:right on meta to work */
  overflow: hidden;        /* contain the float */
}
.bubble-text { display: inline; }
.bubble.in  { background: var(--bg3); border-bottom-left-radius: 4px; }
.bubble.out { background: var(--accent); color: #fff; border-bottom-right-radius: 4px; box-shadow: 0 2px 8px rgba(79,110,247,0.25); }
.bubble.pending { opacity: 0.65; }

/* Text content */
.bubble-text { display: block; }

/* Time + tick row — ALWAYS at the bottom right, never overlapping text */
.bubble-time-row {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  margin-top: 3px;
  min-height: 14px;
}
.bubble-time {
  font-size: 10.5px;
  opacity: 0.65;
  white-space: nowrap;
  font-weight: 400;
  letter-spacing: 0.1px;
}
.bubble.out .bubble-time { color: rgba(255,255,255,0.8); opacity: 1; }
.bubble.in  .bubble-time { color: var(--text3); }

/* ── Bubble meta (time + tick) — float right at end of message ── */
.bubble-meta {
  display: inline-flex;
  align-items: center;
  gap: 0;
  float: right;
  margin-left: 8px;
  margin-top: 4px;
  margin-bottom: -2px;
  line-height: 1;
  opacity: 0.72;
  white-space: nowrap;
}
.bubble-clear {
  display: block;
  clear: both;
  height: 0;
  line-height: 0;
  font-size: 0;
}


/* Status tick SVG icons */
.msg-tick { display: inline-flex; align-items: center; }
.msg-tick svg { width: 14px; height: 10px; }
.tick-sent      svg { stroke: rgba(255,255,255,0.55); }
.tick-delivered svg { stroke: rgba(255,255,255,0.55); }
.tick-seen      svg { stroke: #53d5fd; }
.tick-pending { font-size: 10px; opacity: 0.55; line-height: 1; }

.typing-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; }
.typing-dots { display: flex; gap: 4px; background: var(--bg3); padding: 10px 14px; border-radius: 16px; border-bottom-left-radius: 4px; border: 1px solid var(--border); }
.typing-dots span { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); opacity: 0.5; animation: tdot 1.2s infinite; }
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes tdot { 0%,100%{opacity:0.3;transform:translateY(0)} 50%{opacity:1;transform:translateY(-4px)} }
.typing-label { font-size: 11px; color: var(--text3); font-style: italic; }

.input-area {
  padding: 10px 14px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}
.input-row {
  display: flex;
  align-items: center;  /* center so single-line is vertically centred */
  gap: 8px;
  background: var(--bg4);
  border: 1.5px solid var(--border);
  border-radius: 24px;  /* pill shape */
  padding: 6px 8px 6px 14px;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.input-row:focus-within {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(79,110,247,0.1);
}
.msg-textarea {
  flex: 1;
  background: none;
  border: none;
  outline: none;
  color: var(--text);
  font-size: 14.5px;
  resize: none;
  min-height: 22px;
  max-height: 120px;
  line-height: 1.55;
  padding: 3px 0;
  align-self: center;  /* keeps it centred when single line */
}
.msg-textarea::placeholder { color: var(--text3); }
.send-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  flex-shrink: 0;
  transition: filter 0.15s, transform 0.1s;
}
.send-btn:hover { filter: brightness(1.1); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.35; }

/* ── Account page ─────────────────────────────── */
.account-page {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
}
.page-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.page-header .back-btn { display: none; }
.page-header h2 { font-size: 16px; font-weight: 700; }

.account-body { flex: 1; overflow-y: auto; padding: 16px; padding-bottom: max(32px, env(safe-area-inset-bottom)); scroll-padding-bottom: 20px; }

.profile-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  margin-bottom: 16px;
}
.profile-avatar-wrap { position: relative; flex-shrink: 0; }
.profile-avatar-wrap img, .profile-avatar-wrap .avatar-circle {
  width: 72px; height: 72px;
  border-radius: 50%;
  object-fit: cover;
  border: 3px solid var(--accent);
}
.flash-btn {
  position: absolute;
  bottom: 0; right: -2px;
  width: 24px; height: 24px;
  background: var(--accent);
  border-radius: 50%;
  border: 2px solid var(--bg2);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px;
  cursor: pointer;
}
.flash-btn:hover { filter: brightness(1.15); }
.profile-info { flex: 1; min-width: 0; }
.profile-name { font-size: 20px; font-weight: 800; }
.profile-status { font-size: 13px; color: var(--text2); margin-top: 3px; }

/* Avatar picker */
.avatar-picker {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 16px;
  display: none;
}
.avatar-picker.open { display: block; }
.avatar-grid { display: grid; grid-template-columns: repeat(5,1fr); gap: 8px; } /* 15 avatars = 3 rows × 5 cols */
.av-opt {
  aspect-ratio: 1;
  border-radius: 12px;
  overflow: hidden;
  border: 2px solid var(--border);
  cursor: pointer;
  transition: all 0.15s;
}
.av-opt img { width: 100%; height: 100%; object-fit: cover; display: block; }
.av-opt:hover { border-color: var(--accent); transform: scale(1.05); }
.av-opt.selected { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(79,110,247,0.2); }

/* Settings list */
.settings-list {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  margin-bottom: 14px;
}
.s-row {
  display: flex;
  align-items: center;
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  min-height: 54px;
}
.s-row:last-child { border-bottom: none; }
.s-row.clickable { cursor: pointer; transition: background 0.15s; }
.s-row.clickable:hover { background: var(--bg3); }
.s-icon { font-size: 18px; width: 28px; text-align: center; flex-shrink: 0; }
.s-label { font-size: 13px; font-weight: 600; flex: 1; }
.s-value { font-size: 13px; color: var(--text2); text-align: right; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.s-value.code { font-family: 'SF Mono', 'Fira Code', 'Courier New', monospace; font-size: 12px; color: var(--accent2); letter-spacing: 0.5px; }
.edit-btn {
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 12px;
  color: var(--text2);
  margin-left: 8px;
  flex-shrink: 0;
  transition: all 0.15s;
}
.edit-btn:hover { background: var(--bg3); color: var(--accent); }

/* Inline edit */
.inline-edit {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
}
.inline-edit input {
  flex: 1;
  padding: 6px 10px;
  background: var(--bg4);
  border: 1px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.tick-btn, .cross-btn {
  width: 26px; height: 26px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
  flex-shrink: 0;
  transition: filter 0.15s;
  cursor: pointer;
  border: none;
}
.tick-btn  { background: #22c55e; color: #fff; }
.cross-btn { background: var(--danger); color: #fff; }
.tick-btn:hover  { filter: brightness(1.1); }
.cross-btn:hover { filter: brightness(1.1); }
.tick-btn:disabled { opacity: 0.5; }

/* Toggle */
.toggle {
  width: 40px; height: 22px;
  border-radius: 11px;
  background: var(--bg4);
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle.on { background: var(--accent); }
.toggle::after {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  border-radius: 50%;
  background: #fff;
  top: 3px; left: 3px;
  transition: transform 0.2s;
  box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}
.toggle.on::after { transform: translateX(18px); }

/* Password expand */
.pw-expand { display: none; padding: 12px 16px; background: var(--bg3); border-top: 1px solid var(--border); }
.pw-expand.open { display: block; }

/* Sign out */
.signout-btn {
  width: 100%;
  padding: 14px;
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid rgba(248,113,113,0.2);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.2px;
  transition: all 0.2s;
  margin-top: 4px;
}
.signout-btn:hover { background: var(--danger); color: #fff; box-shadow: 0 4px 14px rgba(248,113,113,0.35); transform: translateY(-1px); }

/* ── Login page ────────────────────────────────── */
.login-page {
  height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: var(--bg);
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
  animation: fadeUp 0.3s ease;
}
@keyframes fadeUp { from{opacity:0;transform:translateY(14px)} to{opacity:1;transform:translateY(0)} }
.login-logo { text-align: center; margin-bottom: 28px; }
.logo-icon {
  width: 62px; height: 62px;
  background: linear-gradient(135deg, var(--accent) 0%, #7b5cf0 100%);
  border-radius: 20px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 28px;
  margin-bottom: 14px;
  box-shadow: 0 6px 24px rgba(79,110,247,0.45), 0 2px 6px rgba(0,0,0,0.2);
}
.login-logo h1 { font-size: 26px; font-weight: 800; }
.login-logo h1 em { color: var(--accent); font-style: normal; }
.login-logo p { font-size: 13px; color: var(--text2); margin-top: 3px; }

.f-group { margin-bottom: 14px; }
.f-label { display: block; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text2); margin-bottom: 6px; }
.f-input {
  width: 100%;
  padding: 12px 14px;
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: 12px;
  color: var(--text);
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
.f-input:focus { border-color: var(--accent); }
.f-input::placeholder { color: var(--text3); }

.btn-primary {
  width: 100%;
  padding: 13px;
  background: linear-gradient(135deg, var(--accent) 0%, #6d5af5 100%);
  color: #fff;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 700;
  transition: all 0.2s;
  margin-top: 4px;
  font-family: inherit;
  cursor: pointer;
  border: none;
  box-shadow: 0 3px 14px rgba(79,110,247,0.35);
  letter-spacing: 0.2px;
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 5px 18px rgba(79,110,247,0.45); }
.btn-primary:disabled { opacity: 0.45; transform: none; cursor: not-allowed; box-shadow: none; }

.btn-google {
  width: 100%;
  padding: 12px;
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: 12px;
  font-size: 14px;
  font-weight: 500;
  display: flex; align-items: center; justify-content: center; gap: 9px;
  transition: all 0.2s;
  margin-top: 8px;
  font-family: inherit;
  cursor: pointer;
  color: var(--text);
}
.btn-google:hover { background: var(--bg3); }

.divider { display: flex; align-items: center; gap: 10px; margin: 14px 0; font-size: 12px; color: var(--text3); }
.divider::before, .divider::after { content:''; flex:1; height:1px; background:var(--border); }

.auth-switch { text-align: center; font-size: 13px; color: var(--text2); margin-top: 16px; }
.auth-switch button { color: var(--accent); font-weight: 600; font-size: 13px; cursor: pointer; background: none; border: none; }

.err-box { padding: 10px 13px; background: var(--danger-bg); border: 1px solid rgba(248,113,113,0.3); border-radius: 10px; color: var(--danger); font-size: 13px; margin-bottom: 14px; }
.ok-box  { padding: 10px 13px; background: rgba(74,222,128,0.1); border: 1px solid rgba(74,222,128,0.25); border-radius: 10px; color: var(--online); font-size: 13px; margin-bottom: 14px; }

/* OTP */
.otp-row { display: flex; gap: 9px; justify-content: center; margin: 12px 0; }
.otp-box {
  width: 48px; height: 58px;
  text-align: center;
  font-size: 24px; font-weight: 900;
  font-family: 'SF Mono', 'Courier New', monospace;
  background: var(--bg4);
  border: 2px solid var(--border);
  border-radius: 14px;
  color: var(--text);
  outline: none;
  transition: all 0.2s;
  caret-color: var(--accent);
}
.otp-box:focus { border-color: var(--accent); background: var(--bg3); box-shadow: 0 0 0 3px rgba(79,110,247,0.1); transform: translateY(-1px); }

/* ── Splash ─────────────────────────────────────── */
#splash {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 9999;
  transition: opacity 0.3s;
}
#splash.out { opacity: 0; pointer-events: none; }
.splash-inner { text-align: center; }
.splash-icon { font-size: 52px; margin-bottom: 20px; }
.spinner {
  width: 28px; height: 28px;
  border: 3px solid rgba(79,110,247,0.2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  margin: 0 auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Toast ─────────────────────────────────────── */
#toast-wrap {
  position: fixed;
  bottom: 20px; right: 20px;
  z-index: 9998;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}
.toast {
  padding: 11px 16px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: fadeUp 0.2s ease;
  pointer-events: all;
}
.toast.info    { background: var(--bg3); color: var(--text); border: 1px solid rgba(255,255,255,0.12); backdrop-filter: blur(8px); }
.toast.success { background: #15803d; color: #86efac; border: 1px solid rgba(134,239,172,0.3); }
.toast.error   { background: #991b1b; color: #fca5a5; border: 1px solid rgba(252,165,165,0.3); }

/* ── Modal ─────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  display: flex; align-items: center; justify-content: center;
  z-index: 500; padding: 20px;
  animation: fadein 0.15s ease;
}
@keyframes fadein { from{opacity:0} to{opacity:1} }
.modal-box {
  background: var(--bg2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 22px;
  padding: 26px;
  width: 100%; max-width: 420px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 4px 12px rgba(0,0,0,0.3);
}
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.modal-head h3 { font-size: 16px; font-weight: 700; }
.modal-close { width: 28px; height: 28px; border-radius: 8px; background: var(--bg4); display: flex; align-items: center; justify-content: center; color: var(--text2); font-size: 13px; cursor: pointer; border: none; }

/* friend search */
.friend-search-row { display: flex; gap: 8px; align-items: center; }
.friend-search-row .f-input { flex: 1; min-width: 0; margin: 0; }
.friend-search-row .btn-primary { flex-shrink: 0; width: auto; padding: 11px 16px; font-size: 13px; }
.found-card { display: flex; align-items: center; gap: 12px; padding: 12px; background: var(--bg3); border-radius: 12px; margin-top: 12px; }
.found-card img, .found-card .avatar-circle { width: 40px; height: 40px; border-radius: 10px; object-fit: cover; }
.found-name { font-weight: 600; }
.found-id   { font-size: 11px; color: var(--accent); font-family: monospace; }

/* request card */
.req-card { display: flex; align-items: center; gap: 12px; padding: 10px; background: var(--bg3); border-radius: 12px; margin-bottom: 8px; }
.req-actions { display: flex; gap: 7px; margin-left: auto; }
.btn-accept  { padding: 6px 13px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 12px; font-weight: 700; border: none; cursor: pointer; }
.btn-decline { padding: 6px 13px; border-radius: 8px; background: var(--bg4); color: var(--text2); font-size: 12px; font-weight: 600; border: none; cursor: pointer; }
.btn-decline:hover { background: var(--danger); color: #fff; }

/* ── Utilities ─────────────────────────────────── */
.hidden { display: none !important; }
.e2e-tag { font-size: 11px; color: var(--online); background: rgba(74,222,128,0.1); padding: 2px 8px; border-radius: 20px; border: 1px solid rgba(74,222,128,0.2); }

/* ── Mobile ─────────────────────────────────────── */
@media (max-width: 700px) {

  /* ── Home (sidebar = full screen) ── */
  .sidebar {
    min-width: 100vw;
    width: 100vw;
    border-right: none;
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .sidebar .contacts-scroll {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
  }
  .sidebar .sidebar-bottom {
    flex-shrink: 0;
    padding: 12px;
    padding-bottom: max(14px, env(safe-area-inset-bottom));
    border-top: 1px solid var(--border);
  }

  /* ── Layout switching ── */
  .main                         { display: none; }
  .app-shell.chat-open .sidebar { display: none; }
  .app-shell.chat-open .main    { display: flex; }
  .app-shell.account-open .sidebar { display: none; }
  .app-shell.account-open .main    { display: flex; }

  /* ── Back buttons visible on mobile ── */
  .chat-header .back-btn  { display: flex; }
  .page-header .back-btn  { display: flex; }
  .friends-header .back-btn { display: flex; }

  /* ── Chat page ── */
  .chat-page {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .messages-area {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px;
    /* Extra bottom padding so last message isn't hidden behind input */
    padding-bottom: 8px;
  }
  .input-area {
    flex-shrink: 0;
    padding: 10px 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
    background: var(--bg2);
    border-top: 1px solid var(--border);
  }

  /* ── Account page ── */
  .account-page {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .account-body {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 16px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  /* ── Friends page ── */
  .friends-page {
    height: 100vh;
    height: 100dvh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .friends-list {
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    padding: 12px 16px;
    padding-bottom: max(24px, env(safe-area-inset-bottom));
  }

  /* ── Messages ── */
  .bubble { max-width: 82%; }
}

/* ── Emoji picker ──────────────────────────────── */
.emoji-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px;
  border-radius: 8px;
  transition: background 0.15s;
  flex-shrink: 0;
}
.emoji-btn:hover { background: var(--bg3); }
.emoji-picker-wrap {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--bg2);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 16px;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5), 0 4px 12px rgba(0,0,0,0.3);
  z-index: 200;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: 280px;
}
.emoji-search-bar {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  display: none; /* hidden by default, shown when search icon clicked */
}
.emoji-search-bar.open { display: block; }
.emoji-search-bar input {
  width: 100%;
  background: var(--bg4);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--text);
  font-size: 13px;
  outline: none;
  font-family: inherit;
}
.emoji-search-bar input:focus { border-color: var(--accent); }
.emoji-category-tabs {
  display: flex;
  gap: 2px;
  padding: 6px 8px;
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.emoji-category-tabs::-webkit-scrollbar { height: 2px; }
.ep-tab {
  background: none;
  border: none;
  font-size: 18px;
  padding: 4px 6px;
  border-radius: 7px;
  cursor: pointer;
  opacity: 0.5;
  flex-shrink: 0;
  transition: all 0.15s;
}
.ep-tab:hover { opacity: 0.9; background: var(--bg4); }
.ep-tab.active { opacity: 1; background: var(--bg4); }
.emoji-scroll-area {
  flex: 1;
  overflow-y: auto;
  padding: 6px;
  overflow-x: hidden;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(34px, 1fr));
  gap: 1px;
  width: 100%;
}
.emoji-grid button {
  font-size: 20px;
  padding: 4px;
  border-radius: 7px;
  background: none;
  border: none;
  cursor: pointer;
  transition: background 0.1s;
  display: flex;
  align-items: center;
  justify-content: center;
  aspect-ratio: 1;
}
.emoji-grid button:hover { background: var(--bg4); }
.input-area { position: relative; }
/* Tab active state */
.ep-tab.active, .ep-tab[style*="border-bottom"] {
  opacity: 1 !important;
}
/* Search input focus */
.ep-picker input:focus {
  border-color: var(--accent) !important;
}

/* ── Unread badge ───────────────────────────────── */
.unread-badge {
  min-width: 22px; height: 22px;
  background: var(--danger);
  border-radius: 11px;
  font-size: 11px; font-weight: 700;
  color: #fff;
  display: flex; align-items: center; justify-content: center;
  padding: 0 5px;
  flex-shrink: 0;
}

/* ── Account inline edit (Doko style) ────────────── */
.s-edit-wrap { display: block; }
.s-edit-right { display: flex; align-items: center; gap: 6px; margin-left: auto; flex-shrink: 0; max-width: 60%; }
.s-label-sm { font-size: 11px; font-weight: 700; color: var(--text3); text-transform: uppercase; letter-spacing: 0.5px; }
.s-inline-edit-area {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}
.s-inline-input {
  flex: 1;
  min-width: 0;
  padding: 6px 10px;
  background: var(--bg4);
  border: 1.5px solid var(--accent);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  font-family: inherit;
}
.s-inline-input:focus { border-color: var(--accent2); }

/* ── Message selection & action bar ─────────────────── */
.msg-row { transition: opacity 0.15s; }
.msg-row.msg-selected { background: rgba(79,110,247,0.08); border-radius: 10px; }

.msg-action-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  animation: fadeUp 0.15s ease;
  width: 100%;
}
/* Icon-only action buttons */
.msg-action-icon-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: transparent;
  color: var(--text2);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
  flex-shrink: 0;
}
.msg-action-icon-btn:hover { background: var(--bg4); color: var(--text); }
.msg-action-icon-btn.active { color: var(--accent); }
.msg-action-icon-btn.active:hover { background: rgba(79,110,247,0.15); color: var(--accent); }
.msg-action-icon-btn.danger { color: var(--danger); }
.msg-action-icon-btn.danger:hover { background: var(--danger-bg); color: var(--danger); }

/* Pinned bar */
.pinned-bar {
  display: none;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(79,110,247,0.08);
  border-bottom: 1px solid rgba(79,110,247,0.15);
  cursor: pointer;
  flex-shrink: 0;
  transition: background 0.15s;
}
.pinned-bar:hover { background: rgba(79,110,247,0.13); }
.pinned-bar.show { display: flex; }
.pinned-bar-text {
  flex: 1;
  font-size: 12px;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.pinned-bubble { outline: 2px solid rgba(79,110,247,0.4); outline-offset: 1px; border-radius: 14px; }

/* ── Friends-since banner ────────────────────────── */
.friends-since-banner {
  color: var(--text2) !important;
  font-size: 11px !important;
  font-style: italic;
  opacity: 0.8;
  margin-bottom: 8px;
}

/* ── Emoji outside input ─────────────────────────── */
.emoji-btn-outer {
  font-size: 22px;
  padding: 7px;
  border-radius: 12px;
  flex-shrink: 0;
  align-self: flex-end;
  margin-bottom: 1px;
  opacity: 0.65;
  transition: all 0.15s;
  background: none;
  border: none;
  cursor: pointer;
}
.emoji-btn-outer:hover { opacity: 1; background: var(--bg3); }

/* ── Chat back button ────────────────────────────── */
.chat-back-btn {
  width: 34px; height: 34px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: rgba(255,255,255,0.08);
  border: none;
  color: var(--text);
  cursor: pointer;
  flex-shrink: 0;
  transition: all 0.15s;
}
.chat-back-btn:hover { background: var(--bg4); transform: translateX(-2px); }
[data-theme="light"] .chat-back-btn { background: rgba(0,0,0,0.06); }
