@import url('https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-behavior: smooth; }

:root {
  /* Lighter dark palette — midway between pitch black and Discord */
  --bg0:         #18191c;
  --bg1:         #1e2024;
  --bg2:         #25272c;
  --bg3:         #2c2f35;
  --bg4:         #34373e;
  --bg-hover:    rgba(255,255,255,.06);
  --bg-active:   rgba(255,255,255,.10);

  --text:        #ecedef;
  --text-dim:    #9a9da3;
  --text-faint:  #5c5f66;

  --accent:      #5b87ff;
  --accent2:     #4169e8;
  --accent-dim:  rgba(91,135,255,.16);
  --accent-glow: rgba(91,135,255,.28);

  --green:       #3ecf8e;
  --red:         #f04f54;
  --amber:       #f4a423;
  --bot:         #9b7fe8;

  --border:      rgba(255,255,255,.09);
  --border-md:   rgba(255,255,255,.14);
  --border-hi:   rgba(255,255,255,.22);

  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   14px;
  --radius-full: 999px;

  --font:        'IBM Plex Sans', -apple-system, sans-serif;
  --font-mono:   'JetBrains Mono', monospace;

  --sidebar-w:   264px;
}

body {
  background: var(--bg0);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 400;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}

::-webkit-scrollbar { width: 5px; background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--border-hi); }

/* ── Auth ─────────────────────────────────────────────────── */

.auth-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background:
    radial-gradient(ellipse 60% 50% at 50% -10%, rgba(91,135,255,.14) 0%, transparent 70%),
    var(--bg0);
}

.auth-wrap { width: 100%; max-width: 430px; padding: 20px; }

.auth-logo {
  font-size: 28px;
  font-weight: 700;
  color: var(--text);
  text-align: center;
  letter-spacing: -0.5px;
  margin-bottom: 4px;
}
.auth-logo span { color: var(--accent); }
.auth-sub { font-size: 14px; color: var(--text-dim); text-align: center; margin-bottom: 32px; font-weight: 500; }

.auth-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  box-shadow: 0 8px 40px rgba(0,0,0,.45);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  border-bottom: 1px solid var(--border);
}

.auth-tab {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 600;
  color: var(--text-dim);
  background: transparent;
  border: none;
  padding: 15px;
  cursor: pointer;
  text-align: center;
  transition: all .15s;
  position: relative;
}
.auth-tab::after {
  content: '';
  position: absolute;
  bottom: -1px; left: 20%; right: 20%;
  height: 2px;
  background: var(--accent);
  border-radius: 2px 2px 0 0;
  transform: scaleX(0);
  transition: transform .15s;
}
.auth-tab.active { color: var(--text); }
.auth-tab.active::after { transform: scaleX(1); }
.auth-tab:hover:not(.active) { color: var(--text); background: var(--bg-hover); }

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

.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 12px; font-weight: 600; color: var(--text-dim); letter-spacing: 0.4px; text-transform: uppercase; }
.field input {
  background: var(--bg3);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 500;
  padding: 11px 14px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
  caret-color: var(--accent);
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }
.field input::placeholder { color: var(--text-faint); font-weight: 400; }

.auth-error { font-size: 13px; color: var(--red); min-height: 16px; font-weight: 600; }
.auth-success { font-size: 13px; color: var(--green); font-weight: 600; }

.auth-btn {
  font-family: var(--font);
  font-size: 15px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: background .15s, box-shadow .15s, transform .1s;
  box-shadow: 0 2px 10px var(--accent-glow);
  margin-top: 4px;
  letter-spacing: 0.1px;
}
.auth-btn:hover { background: var(--accent2); transform: translateY(-1px); box-shadow: 0 4px 18px var(--accent-glow); }
.auth-btn:active { transform: none; }
.auth-btn:disabled { opacity: .5; cursor: not-allowed; transform: none; }

.auth-link-row { font-size: 13px; color: var(--text-dim); text-align: center; }
.auth-link-row a { color: var(--accent); text-decoration: none; font-weight: 600; }
.auth-link-row a:hover { text-decoration: underline; }

/* Email verification step */
.verify-step { text-align: center; padding: 8px 0; }
.verify-step p { font-size: 14px; color: var(--text-dim); margin-bottom: 16px; line-height: 1.6; }
.verify-step strong { color: var(--text); }
.code-input {
  font-family: var(--font-mono);
  font-size: 28px;
  font-weight: 700;
  letter-spacing: 12px;
  text-align: center;
  background: var(--bg3);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  color: var(--accent);
  padding: 14px;
  width: 100%;
  outline: none;
  caret-color: var(--accent);
  transition: border-color .15s;
}
.code-input:focus { border-color: var(--accent); }
.resend-row { margin-top: 12px; font-size: 13px; color: var(--text-dim); }
.resend-btn {
  background: transparent;
  border: none;
  color: var(--accent);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}
.resend-btn:disabled { color: var(--text-faint); cursor: not-allowed; }

/* ── Chat layout ──────────────────────────────────────────── */

.chat-page {
  display: flex;
  height: 100vh;
  overflow: hidden;
  background: var(--bg0);
}

@supports (height: 100dvh) { .chat-page { height: 100dvh; } }

/* ── Sidebar ─────────────────────────────────────────────── */

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg1);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

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

.sidebar-logo {
  font-size: 16px;
  font-weight: 800;
  color: var(--text);
  letter-spacing: -0.3px;
  margin-bottom: 10px;
}
.sidebar-logo span { color: var(--accent); }

.sidebar-user {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background .15s;
}
.sidebar-user:hover { background: var(--bg-hover); }

.sidebar-avatar {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-avatar.accent-bg { background: var(--accent-dim); color: var(--accent); }

.sidebar-username {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.settings-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  padding: 4px;
  border-radius: 4px;
  font-size: 15px;
  transition: color .15s;
  flex-shrink: 0;
}
.settings-btn:hover { color: var(--text); }

.sidebar-scroll { flex: 1; overflow-y: auto; padding: 8px 0; }

.sidebar-section { margin-bottom: 4px; }

.sidebar-section-label {
  font-size: 10px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 0.9px;
  text-transform: uppercase;
  padding: 8px 16px 4px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.sidebar-section-label button {
  background: transparent;
  border: none;
  color: var(--text-faint);
  cursor: pointer;
  font-size: 17px;
  line-height: 1;
  padding: 0 2px;
  transition: color .15s;
}
.sidebar-section-label button:hover { color: var(--text); }

.sidebar-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 14px;
  cursor: pointer;
  transition: background .1s;
  position: relative;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  color: var(--text-dim);
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font);
}
.sidebar-item:hover { background: var(--bg-hover); color: var(--text); }
.sidebar-item.active { background: var(--bg-active); color: var(--text); }

.sidebar-item-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: var(--bg4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-item-avatar img { width: 100%; height: 100%; object-fit: cover; }
.sidebar-item-avatar.bot { background: rgba(155,127,232,.18); color: var(--bot); }

.sidebar-item-name {
  flex: 1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: var(--radius-full);
  flex-shrink: 0;
}

.mute-icon { font-size: 11px; color: var(--text-faint); flex-shrink: 0; }

/* ── Friend context menu ─────────────────────────────────── */

.friend-menu-btn {
  background: transparent;
  border: none;
  color: var(--text-faint);
  font-size: 17px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
  opacity: 0;
  transition: opacity .1s, color .1s;
  flex-shrink: 0;
  line-height: 1;
}
.sidebar-item:hover .friend-menu-btn { opacity: 1; }
.friend-menu-btn:hover { color: var(--text); background: var(--bg-active); }

.friend-ctx-menu {
  position: fixed;
  background: var(--bg3);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 28px rgba(0,0,0,.5);
  z-index: 999;
  min-width: 164px;
  overflow: hidden;
  animation: menuPop .1s ease;
}
@keyframes menuPop {
  from { opacity: 0; transform: scale(.95) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

.ctx-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-family: var(--font);
  font-size: 14px;
  font-weight: 500;
  padding: 10px 14px;
  cursor: pointer;
  text-align: left;
  transition: background .1s, color .1s;
}
.ctx-item:hover { background: var(--bg-hover); color: var(--text); }
.ctx-item.danger { color: var(--red); }
.ctx-item.danger:hover { background: rgba(240,79,84,.1); color: var(--red); }

/* ── Main area ───────────────────────────────────────────── */

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg0);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--text-faint);
}
.empty-state-icon { font-size: 52px; }
.empty-state-title { font-size: 20px; font-weight: 700; color: var(--text-dim); }
.empty-state-sub { font-size: 14px; font-weight: 500; }

/* ── Chat header ─────────────────────────────────────────── */

.chat-header {
  border-bottom: 1px solid var(--border);
  padding: 0 20px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg1);
  flex-shrink: 0;
  gap: 10px;
}

.chat-header-name {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: center;
  gap: 9px;
}
.bot-tag {
  font-size: 10px;
  font-weight: 700;
  color: var(--bot);
  background: rgba(155,127,232,.16);
  padding: 2px 8px;
  border-radius: var(--radius-full);
}

.chat-header-actions { display: flex; gap: 8px; }

.header-btn {
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  padding: 5px 12px;
  cursor: pointer;
  transition: all .15s;
}
.header-btn:hover { color: var(--text); background: var(--bg-hover); }
.header-btn.danger:hover { color: var(--red); border-color: rgba(240,79,84,.4); background: rgba(240,79,84,.08); }

/* ── Messages wrap ───────────────────────────────────────── */

.messages-wrap {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.messages-wrap .messages { flex: 1; min-height: 0; overflow-y: auto; }

.messages {
  overflow-y: auto;
  padding: 16px 0 8px;
  display: flex;
  flex-direction: column;
}

/* ── Date separator ──────────────────────────────────────── */

.date-sep {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-faint);
  letter-spacing: 0.6px;
  text-transform: uppercase;
}
.date-sep::before, .date-sep::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

.sys-msg { font-size: 14px; color: var(--text-faint); text-align: center; padding: 20px; font-style: italic; }

/* ── Messages ────────────────────────────────────────────── */

.msg {
  display: flex;
  gap: 12px;
  padding: 0 20px;
  transition: background .1s;
  position: relative;
}
.msg:hover { background: var(--bg-hover); }
.msg.group-start { padding-top: 14px; }
.msg.consecutive { padding-top: 2px; }
.msg.consecutive .msg-avatar { display: none; }
.msg.consecutive .msg-header { display: none; }
.msg.consecutive .msg-body { padding-left: 48px; }
.msg.unread { background: rgba(91,135,255,.07); transition: background 3s ease; }
.msg.unread.fade-out { background: transparent; }

.msg-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--bg4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  flex-shrink: 0;
  margin-top: 1px;
  overflow: hidden;
  user-select: none;
}
.msg-avatar img { width: 100%; height: 100%; object-fit: cover; }
.msg-avatar.own-av { background: var(--accent-dim); color: var(--accent); }
.msg-avatar.bot-av { background: rgba(155,127,232,.16); color: var(--bot); }

.msg-body { flex: 1; min-width: 0; }
.msg-header { display: flex; align-items: baseline; gap: 8px; margin-bottom: 2px; }
.msg-author { font-size: 15px; font-weight: 700; color: var(--text); }
.msg-author.own { color: var(--accent); }
.msg-author.bot { color: var(--bot); }
.msg-time { font-size: 11px; color: var(--text-faint); font-family: var(--font-mono); }
.msg-content { font-size: 15px; font-weight: 400; color: var(--text); line-height: 1.55; word-break: break-word; white-space: pre-wrap; }

/* ── Message hover actions ───────────────────────────────── */

.msg-hover-actions {
  display: none;
  position: absolute;
  right: 20px;
  top: 50%;
  transform: translateY(-50%);
  background: var(--bg3);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-md);
  padding: 2px 4px;
  gap: 2px;
  align-items: center;
  box-shadow: 0 2px 14px rgba(0,0,0,.4);
  z-index: 10;
}
.msg:hover .msg-hover-actions { display: flex; }

.mha-btn {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 16px;
  cursor: pointer;
  padding: 5px 7px;
  border-radius: var(--radius-sm);
  transition: background .1s, color .1s;
  line-height: 1;
}
.mha-btn:hover { background: var(--bg-hover); color: var(--text); }
.mha-btn.danger:hover { color: var(--red); background: rgba(240,79,84,.1); }

/* ── Reply ───────────────────────────────────────────────── */

.msg-reply-block {
  display: flex;
  align-items: baseline;
  gap: 8px;
  border-left: 3px solid var(--accent);
  padding: 4px 10px;
  margin-bottom: 4px;
  background: rgba(91,135,255,.07);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  cursor: pointer;
}
.msg-reply-author { font-size: 12px; font-weight: 700; color: var(--accent); white-space: nowrap; flex-shrink: 0; }
.msg-reply-content { font-size: 13px; color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.reply-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  flex-shrink: 0;
  font-size: 13px;
}
.reply-bar-label { color: var(--text-dim); flex-shrink: 0; font-weight: 500; }
.reply-bar-label strong { color: var(--accent); }
.reply-bar-preview { color: var(--text-faint); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; }
.reply-bar-cancel {
  background: transparent; border: none; color: var(--text-faint);
  font-size: 17px; cursor: pointer; padding: 2px 6px; border-radius: 4px; flex-shrink: 0;
  transition: color .1s;
}
.reply-bar-cancel:hover { color: var(--red); }

/* ── Edited / Deleted ────────────────────────────────────── */

.msg-edited { font-size: 11px; color: var(--text-faint); font-style: italic; margin-left: 4px; }
.msg-deleted { font-size: 14px; color: var(--text-faint); font-style: italic; font-weight: 300; }

/* ── Reactions ───────────────────────────────────────────── */

.msg-reactions { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }

.reaction-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: var(--bg3);
  border: 1px solid var(--border-md);
  border-radius: 6px;
  padding: 3px 7px;
  font-size: 18px;
  cursor: pointer;
  transition: background .1s, border-color .1s;
  color: var(--text-dim);
  line-height: 1;
  vertical-align: middle;
}
.reaction-btn span { font-size: 12px; font-weight: 700; line-height: 1; display: flex; align-items: center; }
.reaction-btn:hover { background: var(--bg4); border-color: var(--border-hi); }
.reaction-btn.reacted { background: var(--accent-dim); border-color: var(--accent); color: var(--accent); }

/* ── Typing indicator ────────────────────────────────────── */

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 20px 2px;
  flex-shrink: 0;
  min-height: 24px;
}
.typing-name { font-size: 12px; color: var(--text-faint); font-style: italic; font-weight: 500; }
.typing-dots { display: flex; gap: 3px; align-items: center; }
.typing-dots span {
  width: 5px; height: 5px; border-radius: 50%;
  background: var(--text-faint);
  animation: typingBounce 1.2s ease-in-out infinite;
}
.typing-dots span:nth-child(2) { animation-delay: 0.2s; }
.typing-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: .4; }
  30%            { transform: translateY(-4px); opacity: 1; }
}

/* ── Scroll to bottom ────────────────────────────────────── */

.scroll-btn {
  position: absolute;
  bottom: 16px; right: 16px;
  background: var(--bg3);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-full);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  font-weight: 600;
  padding: 8px 14px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  box-shadow: 0 4px 18px rgba(0,0,0,.4);
  transition: background .15s, transform .1s;
  z-index: 10;
}
.scroll-btn:hover { background: var(--bg4); transform: translateY(-1px); }
.scroll-unread {
  background: var(--accent); color: #fff;
  font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: var(--radius-full);
}

/* ── Input bar ───────────────────────────────────────────── */

.input-bar {
  border-top: 1px solid var(--border);
  padding: 12px 16px;
  display: flex;
  align-items: flex-end;
  gap: 10px;
  background: var(--bg1);
  flex-shrink: 0;
}

.input-wrap {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-md);
  display: flex;
  align-items: flex-end;
  padding: 2px 4px 2px 14px;
  gap: 6px;
  transition: border-color .15s, box-shadow .15s;
}
.input-wrap:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-dim); }

.msg-input {
  flex: 1;
  background: transparent;
  border: none;
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  font-weight: 400;
  padding: 9px 0;
  outline: none;
  resize: none;
  caret-color: var(--accent);
  max-height: 140px;
  line-height: 1.5;
}
.msg-input::placeholder { color: var(--text-faint); }

.char-count { font-family: var(--font-mono); font-size: 11px; color: var(--text-faint); align-self: flex-end; padding-bottom: 10px; }
.char-count.warn { color: var(--amber); }
.char-count.over { color: var(--red); }

.emoji-btn {
  font-size: 20px;
  background: transparent;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  height: 40px;
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-end;
  transition: background .15s, border-color .15s;
  display: flex; align-items: center; justify-content: center;
}
.emoji-btn:hover, .emoji-btn.active { background: var(--accent-dim); border-color: var(--accent); }

.gif-btn {
  font-family: var(--font);
  font-size: 12px;
  font-weight: 700;
  color: var(--accent);
  background: transparent;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  padding: 0 12px;
  height: 40px;
  cursor: pointer;
  flex-shrink: 0;
  align-self: flex-end;
  transition: all .15s;
  letter-spacing: 0.5px;
}
.gif-btn:hover, .gif-btn.active { background: var(--accent-dim); border-color: var(--accent); }

.send-btn {
  font-family: var(--font);
  font-size: 14px;
  font-weight: 700;
  color: #fff;
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 18px;
  cursor: pointer;
  transition: background .15s, transform .1s;
  flex-shrink: 0;
  align-self: flex-end;
  height: 40px;
  box-shadow: 0 2px 10px var(--accent-glow);
}
.send-btn:hover { background: var(--accent2); transform: translateY(-1px); }
.send-btn:active { transform: none; }
.send-btn:disabled { opacity: .4; cursor: not-allowed; transform: none; }

.status-strip {
  font-size: 11px;
  color: var(--text-faint);
  border-top: 1px solid var(--border);
  padding: 3px 20px;
  display: flex;
  justify-content: space-between;
  background: var(--bg1);
  flex-shrink: 0;
  font-family: var(--font-mono);
}

/* ── GIF Picker ──────────────────────────────────────────── */

.gif-picker {
  display: none;
  flex-direction: column;
  background: var(--bg2);
  border-top: 1px solid var(--border);
  height: 280px;
  flex-shrink: 0;
}
.gif-picker.open { display: flex; }

.gif-picker-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.gif-search {
  flex: 1;
  background: var(--bg3);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  padding: 7px 12px;
  outline: none;
  caret-color: var(--accent);
  transition: border-color .15s;
}
.gif-search:focus { border-color: var(--accent); }
.gif-search::placeholder { color: var(--text-faint); }

.gif-close-btn {
  background: transparent; border: none; color: var(--text-faint);
  font-size: 17px; cursor: pointer; padding: 4px 8px; border-radius: var(--radius-sm);
  transition: color .15s; flex-shrink: 0;
}
.gif-close-btn:hover { color: var(--text); }

.gif-grid {
  flex: 1; overflow-y: auto;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 4px; padding: 8px; align-content: start;
}

.gif-thumb {
  width: 100%; aspect-ratio: 1;
  object-fit: cover; border-radius: 4px;
  cursor: pointer;
  transition: transform .15s, opacity .15s;
  background: var(--bg4);
}
.gif-thumb:hover { transform: scale(1.04); opacity: .9; }

.gif-loading {
  grid-column: 1/-1; text-align: center;
  padding: 40px; font-size: 13px; color: var(--text-faint); font-style: italic;
}

/* ── GIF in messages ─────────────────────────────────────── */

.msg-gif {
  max-width: 280px; max-height: 200px;
  border-radius: var(--radius-sm);
  display: block; margin-top: 4px; cursor: pointer;
}
.msg-gif:hover { opacity: .9; }

/* ── Emoji picker ────────────────────────────────────────── */

.emoji-picker-wrap {
  position: fixed;
  z-index: 400;
  background: var(--bg2);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-lg);
  padding: 10px;
  width: 340px;
  box-shadow: 0 8px 36px rgba(0,0,0,.5);
  bottom: 80px; left: 16px;
}

.emoji-search-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-family: var(--font);
  font-size: 13px;
  padding: 7px 10px;
  outline: none;
  margin-bottom: 8px;
  caret-color: var(--accent);
}
.emoji-search-input:focus { border-color: var(--accent); }
.emoji-search-input::placeholder { color: var(--text-faint); }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 3px;
  max-height: 260px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  padding-right: 6px;
}
.emoji-grid::-webkit-scrollbar { width: 5px; }
.emoji-grid::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 4px; }

.emoji-cell {
  background: transparent; border: none; font-size: 25px; cursor: pointer;
  padding: 3px; border-radius: 6px; line-height: 1; transition: background .1s;
  display: flex; align-items: center; justify-content: center;
}
.emoji-cell:hover { background: var(--bg4); }

/* ── React picker ────────────────────────────────────────── */

.react-picker-popup {
  position: fixed; z-index: 999;
  background: var(--bg2);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-lg);
  padding: 8px;
  width: 236px;
  box-shadow: 0 8px 36px rgba(0,0,0,.6);
}

.react-emoji-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 2px;
  overflow-y: auto; overflow-x: hidden;
  max-height: 200px;
  scrollbar-width: thin;
  padding-right: 6px;
}
.react-emoji-grid::-webkit-scrollbar { width: 5px; }
.react-emoji-grid::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 4px; }

.react-emoji-cell {
  background: transparent; border: none; font-size: 22px; cursor: pointer;
  padding: 4px; border-radius: 6px; line-height: 1; transition: background .1s;
  display: flex; align-items: center; justify-content: center;
}
.react-emoji-cell:hover { background: var(--bg4); }

/* ── Modals ──────────────────────────────────────────────── */

.modal-backdrop {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.72);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(4px);
}
.modal-backdrop.open { display: flex; }

.modal {
  background: var(--bg2);
  border: 1px solid var(--border-md);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 430px;
  box-shadow: 0 16px 52px rgba(0,0,0,.65);
}

.modal-title { font-size: 18px; font-weight: 700; color: var(--text); margin-bottom: 20px; }

.modal-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }

.btn {
  font-family: var(--font);
  font-size: 14px; font-weight: 700;
  border: none; border-radius: var(--radius-sm);
  padding: 10px 18px; cursor: pointer; transition: all .15s;
}
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 2px 10px var(--accent-glow); }
.btn-primary:hover { background: var(--accent2); }
.btn-ghost { background: var(--bg3); color: var(--text-dim); border: 1px solid var(--border-md); }
.btn-ghost:hover { color: var(--text); background: var(--bg4); }
.btn-danger { background: rgba(240,79,84,.14); color: var(--red); border: 1px solid rgba(240,79,84,.3); }
.btn-danger:hover { background: var(--red); color: #fff; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Friend requests ─────────────────────────────────────── */

.req-list { display: flex; flex-direction: column; gap: 10px; margin-top: 4px; }
.req-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  background: var(--bg3); border-radius: var(--radius-sm); border: 1px solid var(--border);
}
.req-item-name { flex: 1; font-size: 14px; font-weight: 600; }
.req-item-actions { display: flex; gap: 6px; }

/* ── Avatar upload ───────────────────────────────────────── */

.avatar-upload-area {
  border: 2px dashed var(--border-md); border-radius: var(--radius-md);
  padding: 24px; text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s; margin-bottom: 16px;
}
.avatar-upload-area:hover { border-color: var(--accent); background: var(--accent-dim); }
.avatar-preview {
  width: 80px; height: 80px; border-radius: 50%;
  object-fit: cover; margin: 0 auto 10px; display: block;
  border: 2px solid var(--border-md);
}
.avatar-hint { font-size: 13px; color: var(--text-dim); font-weight: 500; }

/* ── Add friend ──────────────────────────────────────────── */

.friend-search-input {
  width: 100%;
  background: var(--bg3); border: 1px solid var(--border-md);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: 14px; padding: 10px 14px;
  outline: none; transition: border-color .15s; caret-color: var(--accent);
  margin-bottom: 12px;
}
.friend-search-input:focus { border-color: var(--accent); }
.friend-search-input::placeholder { color: var(--text-faint); }

/* ── Update Bot card ─────────────────────────────────────── */

.update-card {
  background: var(--bg2); border: 1px solid var(--border-md);
  border-radius: var(--radius-md); padding: 14px 16px; margin-top: 2px; max-width: 440px;
}
.update-title { font-size: 16px; font-weight: 800; color: var(--text); margin-bottom: 6px; letter-spacing: -0.2px; }
.update-desc { font-size: 14px; color: var(--text-dim); margin-bottom: 10px; line-height: 1.5; font-weight: 500; }
.update-changelog {
  list-style: none; display: flex; flex-direction: column; gap: 3px;
  border-top: 1px solid var(--border); padding-top: 10px;
}
.update-cl-separator { height: 1px; background: var(--border); margin: 4px 0; }
.update-cl-item { display: flex; align-items: baseline; gap: 8px; font-size: 14px; line-height: 1.4; }
.cl-icon { font-size: 12px; flex-shrink: 0; width: 14px; font-weight: 700; }

/* ── Admin update modal inputs ───────────────────────────── */

.update-textarea {
  width: 100%;
  background: var(--bg3); border: 1px solid var(--border-md);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: 14px; padding: 12px 14px;
  outline: none; resize: vertical; min-height: 80px; caret-color: var(--accent);
  transition: border-color .15s;
}
.update-textarea:focus { border-color: var(--accent); }
.update-textarea::placeholder { color: var(--text-faint); }

.changelog-row { display: flex; align-items: center; gap: 8px; }
.changelog-icon { font-size: 16px; flex-shrink: 0; width: 20px; text-align: center; }
.changelog-input {
  flex: 1;
  background: var(--bg3); border: 1px solid var(--border-md);
  border-radius: var(--radius-sm); color: var(--text);
  font-family: var(--font); font-size: 13px; padding: 7px 10px;
  outline: none; caret-color: var(--accent);
}
.changelog-input:focus { border-color: var(--accent); }
.changelog-remove {
  background: transparent; border: none; color: var(--text-faint);
  font-size: 14px; cursor: pointer; padding: 4px 6px; border-radius: 4px;
  flex-shrink: 0; transition: color .1s;
}
.changelog-remove:hover { color: var(--red); }

/* ── Invite code ─────────────────────────────────────────── */

.invite-code {
  font-family: var(--font-mono); font-size: 20px; font-weight: 700; color: var(--accent);
  background: var(--bg3); border: 1px solid var(--border-md);
  border-radius: var(--radius-sm); padding: 14px; text-align: center;
  letter-spacing: 3px; margin: 12px 0; cursor: pointer; transition: background .15s;
}
.invite-code:hover { background: var(--accent-dim); }
.invite-hint { font-size: 12px; color: var(--text-faint); text-align: center; font-weight: 500; }

/* ── Misc ────────────────────────────────────────────────── */

.ok  { color: var(--green); }
.err { color: var(--red); }
.msg-content-inner { display: inline; }

/* ── Mobile top bar ──────────────────────────────────────── */

.mobile-topbar {
  display: none;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--bg1);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.mobile-topbar-title { font-size: 17px; font-weight: 800; color: var(--text); }

/* ── Scrollbar ───────────────────────────────────────────── */

::-webkit-scrollbar { width: 5px; background: transparent; }
::-webkit-scrollbar-thumb { background: var(--bg4); border-radius: 99px; }

/* ── Mobile ──────────────────────────────────────────────── */

@supports (height: 100dvh) { .chat-page { height: 100dvh; } }

.input-bar { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
.status-strip { display: none; }

@media (max-width: 600px) {
  .mobile-topbar { display: flex; }
  .chat-page { flex-direction: column; }

  .sidebar {
    position: fixed; inset: 0; width: 100%; z-index: 300;
    transform: translateX(-100%); transition: transform .25s ease;
  }
  .sidebar.mobile-open { transform: translateX(0); }

  .sidebar-backdrop {
    display: none; position: fixed; inset: 0;
    background: rgba(0,0,0,.65); z-index: 299; backdrop-filter: blur(2px);
  }
  .sidebar-backdrop.visible { display: block; }

  .mobile-menu-btn {
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: 1px solid var(--border-md);
    border-radius: var(--radius-sm); color: var(--text-dim);
    font-size: 19px; width: 36px; height: 36px; cursor: pointer; flex-shrink: 0;
  }
  .mobile-menu-btn:hover { color: var(--text); background: var(--bg-hover); }

  .sidebar-close-btn {
    display: flex; align-items: center; justify-content: center;
    background: transparent; border: none; color: var(--text-dim);
    font-size: 21px; cursor: pointer; padding: 4px 8px; margin-left: auto;
  }

  .main { width: 100%; }
  .chat-header { gap: 10px; }
  .input-bar { padding: 10px 10px max(16px, env(safe-area-inset-bottom)); flex-shrink: 0; margin-bottom: 9vh; }
  .send-btn { padding: 10px 14px; }
  .msg-input { font-size: 16px; }
  .field input { font-size: 16px; }
  .modal { max-width: 100%; margin: 16px; }
  #chat-view { height: 100%; display: flex; flex-direction: column; }
  .messages-wrap { flex: 1; min-height: 0; }
}

@media (min-width: 601px) {
  .mobile-menu-btn  { display: none; }
  .sidebar-close-btn { display: none; }
  .sidebar-backdrop { display: none !important; }
}
