:root {
  --bg-deep: #07090e;
  --bg: #0e1219;
  --bg-raised: #161c27;
  --bg-hover: #1e2635;
  --border: #2a3344;
  --text: #eef2f8;
  --text-muted: #8b96ab;
  --accent: #4aa3ff;
  --accent-2: #36d6a2;
  --accent-soft: rgba(74, 163, 255, 0.16);
  --danger: #ff6b7a;
  --danger-soft: rgba(255, 107, 122, 0.14);
  --maria: #f0a0d0;
  --x: #4aa3ff;
  --radius: 14px;
  --font: "Outfit", system-ui, sans-serif;
  --mono: "JetBrains Mono", ui-monospace, monospace;
  --shadow: 0 28px 60px rgba(0, 0, 0, 0.5);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  font-family: var(--font);
  background: var(--bg-deep);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  height: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
[hidden] { display: none !important; }

.login-view {
  height: 100%;
  max-height: 100dvh;
  display: grid;
  place-items: center;
  position: relative;
  overflow: hidden;
  padding: 1.5rem;
}

.login-atmosphere {
  position: absolute;
  inset: 0;
  background:
    radial-gradient(ellipse 70% 55% at 15% 15%, rgba(74, 163, 255, 0.28), transparent 55%),
    radial-gradient(ellipse 60% 45% at 90% 85%, rgba(240, 160, 208, 0.2), transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(54, 214, 162, 0.08), transparent 40%),
    linear-gradient(160deg, #07090e, #121824);
  animation: drift 16s ease-in-out infinite alternate;
  z-index: 0;
}

@keyframes drift {
  from { transform: scale(1) translate(0, 0); }
  to { transform: scale(1.06) translate(-1.5%, 1%); }
}

.login-panel {
  position: relative;
  z-index: 1;
  width: min(100%, 400px);
  background: rgba(14, 18, 25, 0.88);
  backdrop-filter: blur(18px);
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 2rem;
  box-shadow: var(--shadow);
  animation: rise 0.45s ease-out;
}

@keyframes rise {
  from { opacity: 0; transform: translateY(18px); }
  to { opacity: 1; transform: none; }
}

.login-brand { text-align: center; margin-bottom: 1.75rem; }
.login-brand h1 { margin: 0.75rem 0 0.35rem; font-size: 1.7rem; font-weight: 700; letter-spacing: -0.03em; }
.login-brand p { margin: 0; color: var(--text-muted); }

.logo-mark {
  display: inline-grid;
  place-items: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  font-weight: 700;
  background: linear-gradient(135deg, var(--accent), #7b6cf5 50%, var(--maria));
  color: #fff;
  box-shadow: 0 10px 28px rgba(74, 163, 255, 0.35);
}
.logo-mark.sm { width: 40px; height: 40px; font-size: 0.85rem; border-radius: 12px; flex-shrink: 0; }

.login-form, .stack-form { display: flex; flex-direction: column; gap: 1rem; }
.login-form label, .stack-form label {
  display: flex; flex-direction: column; gap: 0.4rem;
  font-size: 0.75rem; font-weight: 600; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.05em;
}

input, textarea, select {
  font: inherit;
  color: var(--text);
  background: var(--bg-deep);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 0.9rem;
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, textarea:focus, select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form-error { margin: 0; color: var(--danger); font-size: 0.9rem; }

.btn-primary, .btn-ghost, .text-btn, .side-action {
  font: inherit; cursor: pointer; border-radius: 10px;
}
.btn-primary {
  font-weight: 600; color: #fff; border: none;
  background: linear-gradient(135deg, #4aa3ff, #5b7cf5);
  padding: 0.85rem 1.2rem;
  transition: filter 0.12s, transform 0.12s;
}
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); }
.btn-ghost {
  font-weight: 500; color: var(--text-muted);
  background: transparent; border: 1px solid var(--border);
  padding: 0.65rem 1rem;
}
.btn-ghost:hover { color: var(--text); background: var(--bg-hover); }
.text-btn {
  border: none; background: none; color: var(--accent);
  font-size: 0.75rem; font-weight: 600; padding: 0;
}
.side-action {
  width: 100%; text-align: left; border: 1px solid transparent;
  background: transparent; color: var(--text-muted);
  padding: 0.5rem 0.65rem; font-weight: 500;
}
.side-action:hover { background: var(--bg-raised); color: var(--text); }

.chat-view {
  display: grid;
  grid-template-columns: 260px 1fr;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  animation: fade-in 0.3s ease;
  position: relative;
}
.chat-view.show-members {
  grid-template-columns: 260px 1fr 220px;
}
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }

.sidebar {
  display: flex; flex-direction: column;
  background: var(--bg-deep);
  border-right: 1px solid var(--border);
  padding: 1rem 0.75rem;
  min-height: 0;
}
.sidebar-brand {
  display: flex; align-items: center; gap: 0.75rem;
  padding: 0.4rem 0.5rem 0.75rem;
}
.sidebar-brand strong { display: block; }
.muted { color: var(--text-muted); font-size: 0.8rem; }

.sidebar-tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  padding: 0 0.25rem 0.65rem;
}
.sidebar-tab {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  padding: 0.45rem 0.3rem;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.28rem;
  position: relative;
}
.sidebar-tab svg { flex-shrink: 0; opacity: 0.85; }
.tab-badge {
  position: absolute;
  top: -3px;
  right: -2px;
  min-width: 16px;
  height: 16px;
  padding: 0 4px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  display: grid;
  place-items: center;
  line-height: 1;
}
.tab-badge[hidden] { display: none !important; }
.unread-pill {
  margin-left: auto;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
  display: inline-grid;
  place-items: center;
}
.room-item.has-unread,
.dm-item.has-unread {
  color: var(--text);
  font-weight: 700;
}
.room-item.has-unread #nav-channel-name,
.dm-item.has-unread .name-highlight {
  font-weight: 700;
}
.user-menu .mi {
  display: inline-block;
  width: 1.25rem;
  text-align: center;
  margin-right: 0.35rem;
  opacity: 0.9;
}
.jump-present {
  position: absolute;
  left: 50%;
  bottom: 5.5rem;
  transform: translateX(-50%);
  z-index: 12;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  padding: 0.45rem 0.9rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  cursor: pointer;
  animation: rise 0.2s ease;
}
.jump-present[hidden] { display: none !important; }
.jump-present:hover { filter: brightness(1.06); }
.sidebar-tab:hover { color: var(--text); background: var(--bg-raised); }
.sidebar-tab.active {
  color: var(--text);
  background: var(--bg-raised);
  border-color: var(--border);
}

.sidebar-nav { flex: 1; overflow-y: auto; min-height: 0; }
.nav-panel { display: flex; flex-direction: column; gap: 2px; }
.nav-panel[hidden] { display: none !important; }
.room-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; color: var(--text-muted);
  padding: 0.35rem 0.65rem 0.45rem;
}
.room-label.row { display: flex; justify-content: space-between; align-items: center; }

.room-item, .dm-item, .friend-chip {
  width: 100%; display: flex; align-items: center; gap: 0.45rem;
  font: inherit; font-weight: 500; color: var(--text-muted);
  background: transparent; border: none; border-radius: 8px;
  padding: 0.5rem 0.65rem; cursor: pointer; text-align: left;
}
.room-item.active, .room-item:hover, .dm-item.active, .dm-item:hover, .friend-chip:hover {
  background: var(--bg-raised); color: var(--text);
}
.hash { color: var(--text-muted); font-weight: 600; }
.dm-list, .friend-list { display: flex; flex-direction: column; gap: 2px; }
.friend-chip .avatar, .dm-item .avatar { width: 22px; height: 22px; font-size: 0.65rem; }

.user-menu-wrap { position: relative; flex-shrink: 0; }
.user-menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 6px);
  min-width: 168px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.45);
  padding: 0.35rem;
  z-index: 50;
  display: flex;
  flex-direction: column;
  gap: 2px;
  animation: pop 0.12s ease-out;
}
.user-menu[hidden] { display: none !important; }
.user-menu button {
  width: 100%;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.88rem;
  font-weight: 500;
  padding: 0.5rem 0.65rem;
  border-radius: 7px;
  cursor: pointer;
}
.user-menu button:hover { background: var(--bg-hover); }
.user-menu button.danger { color: var(--danger); }
.user-menu button.danger:hover { background: var(--danger-soft); }

.sidebar-user {
  display: flex; align-items: center; gap: 0.65rem;
  padding: 0.65rem; border-radius: 12px; background: var(--bg-raised);
  margin-top: 0.5rem;
}
.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  display: grid; place-items: center; font-weight: 700; font-size: 0.85rem;
  color: #fff; flex-shrink: 0; overflow: hidden;
  background: linear-gradient(135deg, #2b7fd4, #5b7cf0);
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.avatar.xl { width: 88px; height: 88px; font-size: 1.8rem; }
.avatar.user-maria { background: linear-gradient(135deg, #c45a9a, #e07ab5); }
.avatar.user-x { background: linear-gradient(135deg, #2b7fd4, #5b7cf0); }
.user-meta { flex: 1; min-width: 0; }
.user-meta strong { display: block; font-size: 0.9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status.online { font-size: 0.75rem; color: var(--accent-2); }

.icon-btn {
  display: grid; place-items: center; width: 32px; height: 32px;
  border: none; border-radius: 8px; background: transparent;
  color: var(--text-muted); cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.chat-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  height: 100%;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  position: relative;
}
.chat-header {
  padding: 0.75rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(10px);
  flex-shrink: 0;
}
.chat-header-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.header-title { min-width: 0; flex: 1; }
.header-search { flex: 1; min-width: 160px; max-width: 280px; }
.header-search input,
.sidebar-search input {
  width: 100%;
  padding: 0.5rem 0.75rem;
  font-size: 0.9rem;
}
.sidebar-search { padding: 0 0.35rem 0.65rem; }
.search-results {
  margin-top: 0.65rem;
  max-height: 180px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg-raised);
}
.search-hit {
  display: block;
  width: 100%;
  text-align: left;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  padding: 0.55rem 0.75rem;
  cursor: pointer;
  font: inherit;
}
.search-hit:last-child { border-bottom: none; }
.search-hit:hover { background: var(--bg-hover); }
.search-hit strong { display: block; font-size: 0.8rem; color: var(--accent); }
.search-hit span { font-size: 0.85rem; color: var(--text-muted); }
.chat-header h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }
.chat-header p { margin: 0.2rem 0 0; }
.header-actions { display: flex; gap: 0.5rem; align-items: center; }
.mobile-only { display: none; }

.notif-banner {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  margin: 0.75rem 1.25rem 0; padding: 0.85rem 1rem;
  border-radius: 12px; border: 1px solid rgba(74, 163, 255, 0.35);
  background: linear-gradient(135deg, rgba(74, 163, 255, 0.12), rgba(54, 214, 162, 0.08));
  animation: rise 0.35s ease;
}
.notif-banner strong { display: block; }
.notif-banner span { color: var(--text-muted); font-size: 0.85rem; }
.notif-actions { display: flex; gap: 0.5rem; flex-shrink: 0; }

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 1rem 0;
  scroll-behavior: auto;
  /* Prevent browser scroll anchoring from jumping the viewport onto loading GIFs/thumbnails */
  overflow-anchor: none;
}

.day-divider {
  display: flex; align-items: center; gap: 1rem;
  margin: 1rem 1.25rem; color: var(--text-muted);
  font-size: 0.72rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em;
}
.day-divider::before, .day-divider::after {
  content: ""; flex: 1; height: 1px; background: var(--border);
}

.message {
  position: relative;
  display: grid; grid-template-columns: 44px 1fr; gap: 0.75rem;
  padding: 0.45rem 1.25rem;
  transition: background 0.12s;
}
.message:hover { background: rgba(255, 255, 255, 0.025); }
.message.deleted { opacity: 0.55; }
.message .avatar { margin-top: 2px; }

.msg-head { display: flex; align-items: baseline; gap: 0.55rem; flex-wrap: wrap; }
.msg-author { font-weight: 600; font-size: 0.95rem; }
.msg-author.user-x { color: var(--x); }
.msg-author.user-maria { color: var(--maria); }
.msg-time { font-size: 0.72rem; color: var(--text-muted); font-family: var(--mono); }
.msg-edited { font-size: 0.72rem; color: var(--text-muted); font-style: italic; }
.msg-body { margin: 0.2rem 0 0; white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.msg-body.deleted-text { font-style: italic; color: var(--text-muted); }
.msg-body a { color: var(--accent); }

.msg-image {
  margin-top: 0.55rem; max-width: min(420px, 100%);
  border-radius: 12px; border: 1px solid var(--border);
  display: block; cursor: zoom-in;
  overflow-anchor: none;
}
.embed-card {
  margin-top: 0.55rem; max-width: min(420px, 100%);
  border: 1px solid var(--border); border-radius: 12px; overflow: hidden;
  background: var(--bg-raised); text-decoration: none; color: inherit;
  display: block; transition: border-color 0.15s, transform 0.12s;
  overflow-anchor: none;
}
.embed-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.embed-card img { width: 100%; display: block; aspect-ratio: 16/9; object-fit: cover; }
.embed-card .embed-meta { padding: 0.65rem 0.8rem; }
.embed-card .embed-meta strong { display: block; font-size: 0.9rem; }
.embed-card .embed-meta span { color: var(--text-muted); font-size: 0.75rem; }
.embed-gif {
  max-width: min(320px, 100%); border-radius: 12px; border: 1px solid var(--border);
  margin-top: 0.55rem; display: block; overflow-anchor: none;
}

.msg-actions {
  position: absolute; top: -10px; right: 1.25rem;
  display: none; gap: 0.25rem;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 8px; padding: 0.2rem;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.35);
}
.message:hover .msg-actions, .message:focus-within .msg-actions { display: flex; }
.msg-actions button {
  font: inherit; font-size: 0.75rem; font-weight: 600;
  color: var(--text-muted); background: transparent; border: none;
  border-radius: 6px; padding: 0.35rem 0.55rem; cursor: pointer;
}
.msg-actions button:hover { background: var(--bg-hover); color: var(--text); }
.msg-actions button.danger:hover { background: var(--danger-soft); color: var(--danger); }

.empty-state {
  display: grid; place-items: center; height: 100%;
  color: var(--text-muted); text-align: center; padding: 2rem;
}
.empty-state strong { display: block; color: var(--text); font-size: 1.1rem; margin-bottom: 0.35rem; }

.composer-wrap {
  position: relative;
  padding: 0.75rem 1.25rem 1.25rem;
  flex-shrink: 0;
  z-index: 5;
}

.typing-indicator {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-height: 1.35rem;
  margin: 0 0 0.45rem 0.15rem;
  font-size: 0.82rem;
  color: var(--text-muted);
  font-weight: 500;
}
.typing-indicator[hidden] { display: none !important; }
.typing-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}
.typing-dots i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  animation: typing-bounce 1.2s ease-in-out infinite;
}
.typing-dots.sm i { width: 4px; height: 4px; }
.typing-dots i:nth-child(2) { animation-delay: 0.15s; }
.typing-dots i:nth-child(3) { animation-delay: 0.3s; }
@keyframes typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.4; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.member-row.is-typing .meta span,
.member-typing {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  color: var(--accent-2);
  font-size: 0.72rem;
}
.member-typing em,
.dm-typing em {
  font-style: normal;
  font-weight: 600;
}

.chan-typing {
  margin-left: auto;
  color: var(--accent-2);
  display: inline-flex;
}
.room-item { position: relative; }
.room-item .chan-typing[hidden] { display: none !important; }

.dm-item {
  align-items: flex-start;
}
.dm-meta {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  min-width: 0;
  flex: 1;
}
.dm-typing {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--accent-2);
  font-size: 0.7rem;
}
.dm-typing[hidden] { display: none !important; }
.dm-item.is-typing .name-highlight { color: var(--text); }

.msg-receipt {
  font-size: 0.7rem;
  font-family: var(--mono);
  color: var(--text-muted);
  margin-left: 0.15rem;
  letter-spacing: 0.02em;
}
.msg-receipt.delivered { color: var(--text-muted); }
.msg-receipt.seen { color: var(--accent, #4aa3ff); }

.admin-privacy {
  margin: 1rem 0;
  padding: 0.85rem 0;
  border-top: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
}
.admin-privacy h4 { margin: 0 0 0.35rem; }
.admin-privacy .small { font-size: 0.82rem; margin: 0 0 0.65rem; }
.privacy-toggles {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem 0.85rem;
  margin-top: 0.35rem;
}
.check.small { font-size: 0.78rem; color: var(--text-muted); }
.profile-popout .last-active { font-size: 0.78rem; margin-top: 0.2rem; }

/* Discord-style popovers (not full-screen) */
.popover {
  position: absolute;
  left: 1.25rem;
  right: 1.25rem;
  bottom: calc(100% - 0.35rem);
  max-width: 420px;
  max-height: min(360px, 45vh);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.55);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 40;
  animation: pop 0.14s ease-out;
}
@keyframes pop {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.popover-head {
  padding: 0.55rem;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.popover-head input {
  width: 100%;
  padding: 0.55rem 0.7rem;
  font-size: 0.9rem;
}
.gif-popover { max-width: 380px; }
.emoji-popover { max-width: 340px; }
.gif-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  padding: 0.5rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.gif-grid button {
  border: 1px solid transparent;
  border-radius: 8px;
  overflow: hidden;
  padding: 0;
  background: var(--bg);
  cursor: pointer;
  aspect-ratio: 1;
}
.gif-grid button:hover { border-color: var(--accent); }
.gif-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }

.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 0.15rem;
  padding: 0.45rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.emoji-grid button {
  font-size: 1.35rem;
  line-height: 1;
  border: none;
  background: transparent;
  border-radius: 6px;
  cursor: pointer;
  padding: 0.35rem;
}
.emoji-grid button:hover { background: var(--bg-hover); }
.emoji-suggest {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  padding: 0.4rem 0.5rem;
  border-bottom: 1px solid var(--border);
  max-height: 90px;
  overflow-y: auto;
}
.emoji-suggest button {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 0.25rem 0.45rem;
  font: inherit;
  font-size: 0.8rem;
  cursor: pointer;
}
.emoji-suggest button:hover { border-color: var(--accent); }

/* Context menu */
.ctx-menu {
  position: fixed;
  z-index: 1000;
  min-width: 200px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.55);
  animation: pop 0.12s ease-out;
}
.ctx-menu button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.5rem;
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  padding: 0.55rem 0.65rem;
  border-radius: 6px;
  cursor: pointer;
}
.ctx-menu button:hover { background: var(--accent); color: #fff; }
.ctx-menu .mi { width: 1.2rem; text-align: center; opacity: 0.9; }
.ctx-menu button.danger { color: var(--danger); }
.ctx-menu button.danger:hover { background: var(--danger); color: #fff; }
.ctx-menu .ctx-sep {
  height: 1px;
  margin: 0.3rem 0.4rem;
  background: var(--border);
}
.ctx-menu .ctx-label {
  padding: 0.35rem 0.65rem 0.2rem;
  font-size: 0.7rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
}

.message.highlight {
  animation: flash 1.2s ease;
  background: rgba(74, 163, 255, 0.12);
}
@keyframes flash {
  0%, 100% { background: transparent; }
  30% { background: rgba(74, 163, 255, 0.18); }
}
.image-preview { position: relative; display: inline-block; margin-bottom: 0.5rem; }
.image-preview img { max-height: 120px; border-radius: 10px; border: 1px solid var(--border); }
.image-preview .icon-btn {
  position: absolute; top: 4px; right: 4px;
  background: rgba(0, 0, 0, 0.65); color: #fff; border-radius: 50%;
}

.composer {
  display: flex; align-items: flex-end; gap: 0.35rem;
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 16px; padding: 0.55rem 0.65rem;
}
.attach-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  color: var(--text-muted); cursor: pointer; border-radius: 8px;
  flex-shrink: 0; border: none; background: transparent;
}
.attach-btn:hover { background: var(--bg-hover); color: var(--text); }
.gif-badge {
  font-size: 0.65rem; font-weight: 800; letter-spacing: 0.04em;
  padding: 0.2rem 0.35rem; border-radius: 6px;
  background: var(--accent-soft); color: var(--accent);
}
.composer textarea {
  flex: 1; resize: none; border: none; background: transparent;
  padding: 0.55rem 0.25rem; max-height: 160px; line-height: 1.4;
  box-shadow: none !important;
}
.composer textarea:focus { border: none; box-shadow: none !important; }
.send-btn {
  display: grid; place-items: center; width: 40px; height: 40px;
  border: none; border-radius: 10px; background: var(--accent);
  color: #fff; cursor: pointer; flex-shrink: 0;
}
.send-btn:hover { filter: brightness(1.1); }

.modal {
  border: none; padding: 0; background: transparent;
  max-width: 480px; width: calc(100% - 2rem);
}
.modal.wide { max-width: 720px; }
.modal.admin-modal { max-width: min(920px, calc(100vw - 1.5rem)); width: 100%; }
.admin-shell {
  padding: 0;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  max-height: min(86vh, 820px);
}
.admin-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: color-mix(in srgb, var(--bg-raised) 88%, var(--accent-soft));
}
.admin-top h3 { margin: 0 0 0.25rem; }
.admin-top .muted { margin: 0; }
.admin-layout {
  display: grid;
  grid-template-columns: 168px 1fr;
  min-height: 0;
  flex: 1;
}
.admin-tabs {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 0.85rem 0.65rem;
  border-right: 1px solid var(--border);
  background: var(--bg-deep);
  overflow-y: auto;
}
.admin-tab {
  text-align: left;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font: inherit;
  font-weight: 600;
  font-size: 0.88rem;
  padding: 0.55rem 0.7rem;
  border-radius: 8px;
  cursor: pointer;
}
.admin-tab:hover { background: var(--bg-raised); color: var(--text); }
.admin-tab.active {
  background: var(--accent-soft);
  color: var(--text);
}
.admin-panels {
  overflow-y: auto;
  padding: 1.1rem 1.25rem 1.35rem;
  min-height: 0;
}
.admin-panel[hidden] { display: none !important; }
.admin-panel h4 { margin: 0 0 0.35rem; }
.admin-panel > .muted { margin: 0 0 1rem; }
.admin-form { max-width: 420px; }
.admin-stat-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}
.admin-stat-card {
  padding: 0.9rem 1rem;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
}
.admin-stat-card strong {
  display: block;
  font-size: 1.35rem;
  margin-bottom: 0.15rem;
}
.admin-stat-card span { color: var(--text-muted); font-size: 0.82rem; }
.brand-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  border-radius: 12px;
  border: 1px dashed var(--border);
  background: var(--bg-deep);
  margin: 0.25rem 0 0.75rem;
}
.brand-preview strong { display: block; }
.channel-edit-btn {
  display: inline-grid;
  vertical-align: middle;
  margin-left: 0.25rem;
  width: 26px;
  height: 26px;
}
#room-heading { display: flex; align-items: center; gap: 0.2rem; flex-wrap: wrap; }
@media (max-width: 720px) {
  .admin-layout { grid-template-columns: 1fr; }
  .admin-tabs {
    flex-direction: row;
    flex-wrap: wrap;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .admin-stat-grid { grid-template-columns: 1fr; }
}
.modal::backdrop { background: rgba(0, 0, 0, 0.7); backdrop-filter: blur(5px); }
.modal-card {
  background: var(--bg-raised); border: 1px solid var(--border);
  border-radius: 18px; padding: 1.25rem; box-shadow: var(--shadow);
}
.modal-card h3 { margin: 0 0 1rem; font-size: 1.15rem; }
.modal-card h4 { margin: 1rem 0 0.5rem; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-muted); }
.modal-actions { display: flex; justify-content: flex-end; gap: 0.5rem; margin-top: 1rem; }

.profile-layout { display: grid; grid-template-columns: 140px 1fr; gap: 1.25rem; }
.profile-avatar-block { display: flex; flex-direction: column; align-items: center; gap: 0.75rem; }
.file-label { display: inline-block; cursor: pointer; text-align: center; }

.friends-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1.25rem; }
.inline-form { display: flex; gap: 0.5rem; align-items: center; }
.inline-form.wrap { flex-wrap: wrap; }
.inline-form input, .inline-form select { flex: 1; min-width: 120px; }
.check { display: flex; align-items: center; gap: 0.4rem; font-size: 0.85rem; color: var(--text-muted); text-transform: none; letter-spacing: 0; }

.mini-list { display: flex; flex-direction: column; gap: 0.45rem; max-height: 260px; overflow-y: auto; }
.mini-row {
  display: flex; align-items: center; gap: 0.55rem;
  padding: 0.55rem 0.65rem; border-radius: 10px; background: var(--bg);
  border: 1px solid var(--border);
}
.mini-row .grow { flex: 1; min-width: 0; }
.mini-row strong { display: block; font-size: 0.9rem; }
.mini-row span { font-size: 0.75rem; color: var(--text-muted); }
.mini-row .row-actions { display: flex; gap: 0.35rem; }

.admin-users { margin-top: 1rem; display: flex; flex-direction: column; gap: 0.5rem; max-height: 320px; overflow-y: auto; }

.lightbox { border: none; padding: 0; background: transparent; max-width: 95vw; max-height: 95vh; }
.lightbox::backdrop { background: rgba(0, 0, 0, 0.88); }
.lightbox img { max-width: 90vw; max-height: 85vh; border-radius: 8px; display: block; }
.lightbox-close {
  position: fixed; top: 1rem; right: 1rem; width: 40px; height: 40px;
  border: none; border-radius: 50%; background: rgba(255, 255, 255, 0.1);
  color: #fff; font-size: 1.5rem; cursor: pointer;
}

@media (max-width: 820px) {
  .chat-view { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .mobile-only { display: inline-flex; }
  .profile-layout, .friends-grid { grid-template-columns: 1fr; }
  .notif-banner { flex-direction: column; align-items: flex-start; }
}

/* Layout with members rail */
.nav-section {
  margin-bottom: 0.35rem;
  padding-bottom: 0.35rem;
  border-bottom: 1px solid rgba(42, 51, 68, 0.55);
}
.nav-section:last-child { border-bottom: none; }

.members-panel {
  display: none;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-deep);
  border-left: 1px solid var(--border);
  padding: 0.85rem 0.65rem;
}
.chat-view.show-members .members-panel {
  display: flex;
}
.members-panel[hidden] { display: none !important; }
.members-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  padding: 0.25rem 0.15rem 0.65rem 0.5rem;
}
#toggle-members.active {
  color: var(--accent);
  background: var(--bg-hover);
}
.members-list {
  overflow-y: auto;
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.member-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 0.4rem 0.5rem;
  border-radius: 8px;
  cursor: pointer;
}
.member-row:hover { background: var(--bg-raised); }
.member-row .avatar { width: 28px; height: 28px; font-size: 0.7rem; }
.member-row .meta strong { display: block; font-size: 0.88rem; }
.member-row .meta span { font-size: 0.7rem; color: var(--text-muted); }
.member-row .badge {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 700;
  color: var(--accent);
}

/* Replies */
.reply-snippet {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  margin-bottom: 0.25rem;
  padding: 0.25rem 0.45rem;
  border-left: 3px solid var(--accent);
  border-radius: 0 8px 8px 0;
  background: rgba(74, 163, 255, 0.08);
  cursor: pointer;
  font-size: 0.8rem;
  color: var(--text-muted);
  max-width: 100%;
}
.reply-snippet strong { color: var(--accent); font-weight: 600; }
.reply-snippet span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-bar {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  margin-bottom: 0.45rem;
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  border-left: 3px solid var(--accent);
}
.reply-bar-text { flex: 1; min-width: 0; }
.reply-bar-text strong { display: block; font-size: 0.85rem; }
.reply-bar-text span {
  display: block;
  font-size: 0.8rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Mentions */
.mention {
  color: #c9e3ff;
  background: rgba(74, 163, 255, 0.22);
  border-radius: 4px;
  padding: 0 0.2rem;
  font-weight: 600;
  cursor: pointer;
}
.mention.me {
  background: rgba(250, 168, 26, 0.28);
  color: #ffe6a8;
}
.message.mention-flash {
  background: rgba(250, 168, 26, 0.1);
}

.mention-suggest {
  position: absolute;
  left: 1.25rem;
  right: 1.25rem;
  bottom: calc(100% - 0.2rem);
  max-width: 280px;
  max-height: 200px;
  overflow-y: auto;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
  z-index: 45;
  padding: 0.25rem;
}
.mention-suggest button {
  display: flex;
  width: 100%;
  align-items: center;
  gap: 0.45rem;
  border: none;
  background: transparent;
  color: var(--text);
  font: inherit;
  text-align: left;
  padding: 0.45rem 0.55rem;
  border-radius: 6px;
  cursor: pointer;
}
.mention-suggest button:hover,
.mention-suggest button.active { background: var(--accent); color: #fff; }
.mention-suggest .avatar { width: 22px; height: 22px; font-size: 0.65rem; }

/* Toasts — single live message notification + occasional system toasts */
.toast-stack {
  position: fixed;
  top: max(0.75rem, env(safe-area-inset-top, 0px));
  right: max(0.75rem, env(safe-area-inset-right, 0px));
  z-index: 2000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  width: min(360px, calc(100vw - 1.5rem));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  text-align: left;
  font: inherit;
  color: inherit;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: 14px;
  padding: 0.85rem 1rem;
  box-shadow: var(--shadow);
  cursor: pointer;
  animation: toast-in 0.2s ease;
}
.toast.live-toast {
  border-left-width: 4px;
}
.toast.mention { border-left-color: #faa81a; }
.toast.dm { border-left-color: var(--accent-2); }
.toast strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 700;
  line-height: 1.25;
  margin-bottom: 0.2rem;
}
.toast span {
  display: block;
  font-size: 0.84rem;
  color: var(--text-muted);
  line-height: 1.35;
}
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: none; }
}

@media (max-width: 820px) {
  .toast-stack {
    top: auto;
    right: max(0.65rem, env(safe-area-inset-right, 0px));
    left: max(0.65rem, env(safe-area-inset-left, 0px));
    bottom: calc(5.5rem + env(safe-area-inset-bottom, 0px));
    width: auto;
  }
  .toast {
    padding: 1rem 1.1rem;
    border-radius: 16px;
    min-height: 3.25rem;
  }
  .toast strong { font-size: 1rem; }
  .toast span { font-size: 0.9rem; }
  @keyframes toast-in {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: none; }
  }
}

.admin-stats {
  margin-bottom: 0.85rem;
  font-size: 0.85rem;
}
.admin-purge {
  margin-top: 1rem;
  padding-top: 0.75rem;
  border-top: 1px solid var(--border);
}
.danger-outline { border-color: rgba(255, 107, 122, 0.45) !important; color: var(--danger) !important; }
.danger-outline:hover { background: var(--danger-soft) !important; }
.settings-check {
  flex-direction: row !important;
  align-items: center;
  text-transform: none !important;
  letter-spacing: 0 !important;
  font-size: 0.9rem !important;
  color: var(--text) !important;
  font-weight: 500 !important;
}

@media (max-width: 1100px) {
  .chat-view { grid-template-columns: 240px 1fr; }
  .chat-view.show-members { grid-template-columns: 240px 1fr; }
  .members-panel { display: none; }
  .chat-view.show-members .members-panel:not([hidden]) {
    display: flex;
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 220px;
    z-index: 30;
    box-shadow: var(--shadow);
  }
}
@media (max-width: 820px) {
  .chat-view { grid-template-columns: 1fr; }
}

/* —— Light mode —— */
html[data-theme="light"] {
  --bg-deep: #e8ecf4;
  --bg: #f4f6fb;
  --bg-raised: #ffffff;
  --bg-hover: #e6ebf5;
  --border: #c9d2e3;
  --text: #1a2233;
  --text-muted: #5c6b82;
  --accent: #2b7fd4;
  --accent-2: #0f9f6e;
  --accent-soft: rgba(43, 127, 212, 0.14);
  --danger: #d6455d;
  --danger-soft: rgba(214, 69, 93, 0.12);
  --shadow: 0 20px 40px rgba(30, 50, 80, 0.12);
}
html[data-theme="light"] .login-atmosphere {
  background:
    radial-gradient(ellipse 70% 55% at 15% 15%, rgba(43, 127, 212, 0.2), transparent 55%),
    radial-gradient(ellipse 60% 45% at 90% 85%, rgba(224, 122, 181, 0.16), transparent 50%),
    linear-gradient(160deg, #dfe6f2, #f4f6fb);
}
html[data-theme="light"] .login-panel {
  background: rgba(255, 255, 255, 0.92);
}
html[data-theme="light"] .chat-header {
  background: color-mix(in srgb, var(--bg) 94%, #ffffff);
}
html[data-theme="light"] .notif-banner {
  background: var(--bg-raised);
  border-color: var(--border);
}

/* Presence */
.avatar-wrap {
  position: relative;
  flex-shrink: 0;
}
.presence-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-raised);
  background: var(--accent-2);
}
.presence-dot.online { background: #23a55a; }
.presence-dot.idle { background: #f0b232; }
.presence-dot.dnd { background: #f23f43; }
.presence-dot.offline { background: #80848e; }
.status-line {
  display: block;
  width: 100%;
  border: none;
  background: transparent;
  padding: 0;
  text-align: left;
  cursor: pointer;
  color: inherit;
  font: inherit;
}
.status-line:hover span { color: var(--text); }

/* Highlighted usernames */
.msg-author.has-highlight,
.member-row .meta strong.has-highlight,
.name-highlight {
  font-weight: 700;
}
.hl-badge {
  display: inline-block;
  margin-left: 0.35rem;
  padding: 0.05rem 0.35rem;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--accent-soft);
  color: var(--accent);
  vertical-align: middle;
}

/* DM row with close */
.dm-item {
  position: relative;
  padding-right: 1.8rem;
}
.dm-item .dm-x {
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  font-size: 0.9rem;
  line-height: 1;
}
.dm-item:hover .dm-x { opacity: 1; }
.dm-item .dm-x:hover { background: var(--danger-soft); color: var(--danger); }

/* Profile popout */
.profile-popout {
  position: fixed;
  z-index: 1500;
  width: 280px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: var(--shadow);
  overflow: hidden;
  animation: pop 0.12s ease;
}
.profile-popout .banner {
  height: 56px;
  background: linear-gradient(135deg, var(--accent), #7b6cf5 55%, var(--maria, #e07ab5));
}
.profile-popout .body { padding: 0 0.85rem 0.85rem; }
.profile-popout .avatar-lg {
  width: 64px;
  height: 64px;
  margin-top: -28px;
  border: 4px solid var(--bg-raised);
  border-radius: 50%;
  font-size: 1.4rem;
}
.profile-popout .avatar-wrap-lg {
  position: relative;
  display: inline-block;
}
.profile-popout .presence-dot {
  width: 16px;
  height: 16px;
  right: 2px;
  bottom: 2px;
  border-width: 3px;
}
.profile-popout h4 {
  margin: 0.55rem 0 0.15rem;
  font-size: 1.05rem;
}
.profile-popout .uname { color: var(--text-muted); font-size: 0.85rem; }
.profile-popout .bio {
  margin: 0.55rem 0 0;
  font-size: 0.85rem;
  color: var(--text-muted);
  white-space: pre-wrap;
}
.profile-popout .custom {
  margin-top: 0.35rem;
  font-size: 0.85rem;
}
.profile-popout .actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.75rem;
}
.profile-popout .actions button {
  font: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 8px;
  padding: 0.4rem 0.55rem;
  cursor: pointer;
}
.profile-popout .actions button:hover { border-color: var(--accent); }
.profile-popout .actions button.danger { color: var(--danger); }

.view-profile-card { padding: 0; overflow: hidden; max-width: 380px; }
.view-profile-banner {
  height: 72px;
  background: linear-gradient(135deg, var(--bg-hover), var(--accent-soft));
}
.view-profile-banner.has-color { opacity: 0.9; }
.view-profile-body {
  padding: 0 1.25rem 0.5rem;
  margin-top: -36px;
}
.view-profile-body .avatar-wrap-lg {
  position: relative;
  display: inline-block;
  margin-bottom: 0.65rem;
}
.view-profile-body .avatar.xl {
  border: 4px solid var(--bg-raised);
}
.view-profile-body .presence-dot {
  width: 16px;
  height: 16px;
  right: 4px;
  bottom: 4px;
  border-width: 3px;
}
.view-profile-body h3 {
  margin: 0 0 0.2rem;
  font-size: 1.25rem;
}
.view-profile-bio {
  margin: 0.75rem 0;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-word;
}
.view-profile-actions {
  justify-content: flex-start;
  flex-wrap: wrap;
  padding: 0;
  margin-bottom: 0.5rem;
}
.view-profile-card > .modal-actions {
  padding: 0 1.25rem 1.1rem;
}

.dm-item-wrap {
  position: relative;
  display: flex;
  align-items: center;
}
.dm-item-wrap .dm-item {
  flex: 1;
  padding-right: 1.8rem;
}
.dm-item-wrap .dm-x {
  position: absolute;
  right: 0.25rem;
  top: 50%;
  transform: translateY(-50%);
  width: 22px;
  height: 22px;
  border: none;
  border-radius: 4px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  opacity: 0;
  font-size: 0.95rem;
  z-index: 2;
}
.dm-item-wrap:hover .dm-x { opacity: 1; }
.dm-item-wrap .dm-x:hover { background: var(--danger-soft); color: var(--danger); }
.dm-item .avatar-wrap, .friend-chip .avatar-wrap {
  width: 22px;
  height: 22px;
}
.dm-item .avatar-wrap .avatar, .friend-chip .avatar-wrap .avatar {
  width: 22px;
  height: 22px;
  font-size: 0.65rem;
}
.dm-item .presence-dot, .friend-chip .presence-dot {
  width: 8px;
  height: 8px;
  border-width: 1.5px;
}
