:root {
  --bg: #0f0f12;
  --surface: #18181f;
  --surface-hover: #22222c;
  --border: #2a2a36;
  --text: #e8e8ed;
  --text-muted: #8888a0;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --system: #22c55e;
  --you: #3b82f6;
  --radius: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  overflow-x: hidden;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: 'JetBrains Mono', monospace;
  background: var(--bg);
  color: var(--text);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  overflow-x: hidden;
  max-width: 100vw;
}

.screen {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}
.hidden {
  display: none !important;
}

/* Welcome */
.welcome-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem 2.5rem;
  box-shadow: var(--shadow);
  width: 100%;
  max-width: 380px;
}
.welcome-card h1 {
  font-family: 'Unbounded', sans-serif;
  font-size: 1.5rem;
  margin-bottom: 0.5rem;
  background: linear-gradient(135deg, var(--accent), #a78bfa);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.welcome-card p,
.auth-hint {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-bottom: 1.25rem;
}
.auth-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}
.auth-tab {
  font: inherit;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.auth-tab:hover,
.auth-tab.active {
  color: var(--text);
  border-color: var(--accent);
  background: var(--surface-hover);
}
.auth-error {
  color: #ef4444;
  font-size: 0.85rem;
  margin-top: -0.25rem;
}
.auth-error.hidden {
  display: none;
}
.welcome-card form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.welcome-card input,
.welcome-card input[type="password"] {
  font: inherit;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.welcome-card input:focus {
  border-color: var(--accent);
}
.welcome-card button,
#auth-submit {
  font: inherit;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
}
.welcome-card button:hover {
  background: var(--accent-hover);
}

.forgot-password-link {
  display: block;
  margin-top: 0.75rem;
  font-size: 0.85rem;
  color: var(--text-muted);
  text-decoration: none;
  text-align: center;
}
.forgot-password-link:hover { color: var(--accent); }

#forgot-step-request input,
#forgot-step-reset input {
  width: 100%;
  margin-bottom: 0.5rem;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
#forgot-request-btn,
#forgot-reset-btn {
  width: 100%;
  margin-top: 0.25rem;
}

/* ===== Chat layout ===== */
#chat {
  display: grid;
  grid-template-columns: 260px 1fr;
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "header header"
    "sidebar main";
  height: 100%;
  min-height: 0;
  max-height: 100vh;
  max-height: 100dvh;
  overflow: hidden;
  align-items: stretch;
  justify-content: stretch;
  max-width: 100vw;
}
#chat.hidden {
  display: none;
}

.chat-header {
  grid-area: header;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  min-width: 0;
  max-width: 100%;
}
.header-back-btn {
  display: none;
  margin-right: 0.25rem;
  padding: 0.4rem 0.6rem;
  font-size: 1.25rem;
  line-height: 1;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
}
.header-back-btn:hover {
  background: var(--surface-hover);
  color: var(--accent);
}
.my-profile-link {
  font-family: 'Unbounded', sans-serif;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  color: var(--accent);
  text-decoration: none;
  padding: 0.35rem 0.5rem;
  border-radius: 6px;
  transition: background 0.2s, color 0.2s;
  white-space: nowrap;
}
.my-profile-link:hover {
  background: var(--surface-hover);
  color: var(--accent-hover);
}

.chat-header h1 {
  font-family: 'Unbounded', sans-serif;
  font-size: 1.1rem;
  font-weight: 600;
}
.online {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--text-muted);
  font-size: 0.85rem;
}
.online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--system);
  animation: pulse 2s infinite;
}
@keyframes pulse {
  50% { opacity: 0.6; }
}

/* ===== Sidebar ===== */
.sidebar {
  grid-area: sidebar;
  border-right: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}

.sidebar-section {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.sidebar-profile-section {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
}
.sidebar-profile-link {
  display: block;
  font-size: 0.9rem;
  color: var(--accent);
  text-decoration: none;
  padding: 0.35rem 0;
}
.sidebar-profile-link:hover { text-decoration: underline; }

.sidebar-section:first-child {
  border-bottom: 1px solid var(--border);
}

.sidebar-section-btn {
  font-family: 'Unbounded', sans-serif;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.85rem 1rem;
  border: none;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  text-align: left;
  position: relative;
}
.sidebar-section-btn:hover {
  background: var(--surface-hover);
}
.sidebar-section-btn.open {
  background: var(--surface);
}

.sidebar-section-arrow {
  font-size: 0.6rem;
  transition: transform 0.25s ease;
  display: inline-block;
  line-height: 1;
}
.sidebar-section-btn:not(.open) .sidebar-section-arrow {
  transform: rotate(-90deg);
}

.sidebar-section-badge {
  display: none;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: #ef4444;
  color: white;
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.6rem;
  font-weight: 600;
  align-items: center;
  justify-content: center;
  padding: 0 5px;
  margin-left: auto;
}
.sidebar-section-badge.visible {
  display: inline-flex;
}

.sidebar-section-body {
  padding: 0.5rem 0.75rem 0.75rem;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  min-height: 0;
}
.sidebar-section-body.collapsed {
  display: none;
}

.header-center {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 0;
}
.header-discussion-name {
  font-size: 0.9rem;
  color: var(--text-muted);
}
.header-status {
  font-size: 0.7rem;
  color: var(--text-muted);
  min-height: 1em;
}
.header-status.online-text {
  color: var(--system);
}
.header-status.typing-text {
  color: var(--accent);
}
.nick-link {
  cursor: pointer;
  text-decoration: none;
}
.header-discussion-name.group-link {
  cursor: pointer;
}
.header-discussion-name.group-link:hover {
  color: var(--text);
}
.header-discussion-name.channel-link {
  cursor: pointer;
}
.header-discussion-name.channel-link:hover {
  color: var(--text);
}
.msg-views {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-left: 0.25rem;
}
.channels-discover-btn {
  margin-top: 0.5rem;
  width: 100%;
}
.channels-discover-list,
.channel-subscribers-list {
  list-style: none;
  margin: 0;
  padding: 0;
  max-height: 60vh;
  overflow-y: auto;
}
.channel-discover-item,
.channel-subscriber-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.channel-discover-item span:first-child { flex: 1; }
.channel-creator { font-size: 0.8rem; color: var(--text-muted); }
.channel-subscriber-item a { color: var(--accent); text-decoration: none; }
.channel-subscriber-item a:hover { text-decoration: underline; }

.mobile-bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 0.5rem 0 max(0.5rem, env(safe-area-inset-bottom)) 0;
  z-index: 100;
  flex-direction: row;
  justify-content: space-around;
  align-items: center;
}
.mobile-bottom-nav:not(.hidden) {
  display: flex;
}
.mobile-nav-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.2rem;
  font-size: 0.65rem;
  color: var(--text-muted);
  background: none;
  border: none;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  text-decoration: none;
  color: inherit;
  font: inherit;
}
.mobile-nav-btn.active { color: var(--accent); font-weight: 600; }
.mobile-nav-btn span { font-size: 0.65rem; }

.mobile-list-view {
  display: none;
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}
.mobile-list-view:not(.hidden) {
  display: block;
}
.mobile-list-view.hidden { display: none !important; }
.mobile-list-title {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.mobile-hint {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}
.mobile-search-input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.75rem;
  font: inherit;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}
.mobile-dm-search-wrap { margin-bottom: 0.75rem; }
.mobile-tab-panel {
  display: none;
  height: 100%;
}
.mobile-tab-panel:not(.hidden) {
  display: block;
}
.mobile-tab-panel.hidden { display: none !important; }
.mobile-list-ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.mobile-list-item {
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  font-size: 0.95rem;
}
.mobile-list-item:hover { background: var(--surface-hover); }
.mobile-channel-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
}
.mobile-channel-row .channel-sub-btn { flex-shrink: 0; }
.mobile-block { margin-bottom: 1.5rem; }
.mobile-list-h3 {
  font-size: 0.75rem;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.nick-link:hover {
  text-decoration: underline;
}

/* Discussions list */
.create-discussion-btn {
  font: inherit;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  border: 1px dashed var(--border);
  border-radius: 8px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.create-discussion-btn:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}
.create-discussion-form {
  margin-bottom: 0.5rem;
}
.create-discussion-form.hidden {
  display: none;
}
.create-discussion-form input {
  font: inherit;
  width: 100%;
  padding: 0.5rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}
.create-discussion-actions {
  display: flex;
  gap: 0.5rem;
}
.create-discussion-actions button {
  font: inherit;
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  font-size: 0.85rem;
}
.create-discussion-actions button:first-child {
  background: var(--accent);
  color: white;
}
.create-discussion-actions button:last-child {
  background: var(--surface-hover);
  color: var(--text-muted);
}
#discussions-list {
  list-style: none;
  overflow-y: auto;
}
.discussion-item {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  margin-bottom: 2px;
}
.discussion-item:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.discussion-item.active {
  background: var(--accent);
  color: white;
}

/* DM search & contacts */
.dm-search-wrap { margin-bottom: 0.5rem; }
.dm-search-wrap input {
  font: inherit;
  width: 100%;
  padding: 0.4rem 0.5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  font-size: 0.8rem;
}
.dm-search-wrap input:focus { border-color: var(--accent); }
#dm-search-results, #dm-contacts { list-style: none; }
#dm-search-results.hidden { display: none; }

.dm-contact {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.2s, color 0.2s;
  margin-bottom: 2px;
}
.dm-contact:hover {
  background: var(--surface-hover);
  color: var(--text);
}
.dm-contact.active {
  background: var(--accent);
  color: white;
}
.dm-contact-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex: 1;
}
.dm-contact-name {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dm-contact-last {
  font-size: 0.7rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 0.15rem;
}
.dm-contact.active .dm-contact-last {
  color: rgba(255,255,255,0.7);
}
.unread-badge {
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  background: var(--accent);
  color: white;
  font-size: 0.65rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
  flex-shrink: 0;
  margin-left: 0.5rem;
}
.dm-contact.active .unread-badge {
  background: white;
  color: var(--accent);
}

/* ===== Chat main area ===== */
.chat-main {
  grid-area: main;
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}

.messages {
  flex: 1 1 0;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  min-height: 0;
}

.msg {
  max-width: 75%;
  padding: 0.6rem 1rem;
  border-radius: var(--radius);
  font-size: 0.9rem;
  line-height: 1.4;
  word-break: break-word;
  flex-shrink: 0;
}
.msg.system {
  align-self: center;
  background: transparent;
  color: var(--text-muted);
  font-size: 0.8rem;
}
.msg.user {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
}
.msg.user .nick {
  font-size: 0.75rem;
  color: var(--accent);
  margin-bottom: 0.2rem;
  display: flex;
  align-items: center;
  gap: 0.4rem;
}
.nick-creator {
  color: #22c55e !important;
  font-weight: 500;
}
.nick-admin {
  color: #f59e0b !important;
}
.role-tag {
  font-size: 0.6rem;
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}
.creator-tag {
  background: rgba(34, 197, 94, 0.15);
  color: #22c55e;
}
.admin-tag {
  background: rgba(245, 158, 11, 0.15);
  color: #f59e0b;
}
.msg.own {
  align-self: flex-end;
  background: var(--you);
  border: none;
  color: white;
}
.msg.own .nick {
  color: rgba(255,255,255,0.9);
}
.msg .time {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  display: inline-flex;
  align-items: center;
  gap: 2px;
}
.msg.own .time {
  color: rgba(255,255,255,0.7);
}
.msg audio {
  display: block;
  margin: 0.25rem 0;
  max-width: 100%;
  height: 36px;
}

/* ===== Send form — pinned to bottom ===== */
.send-form {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  position: relative;
}
.send-form input {
  flex: 1;
  font: inherit;
  padding: 0.75rem 1rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}
.send-form input:focus {
  border-color: var(--accent);
}
.send-form button {
  font: inherit;
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 8px;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-weight: 500;
  transition: background 0.2s;
  flex-shrink: 0;
}
.send-form button:hover {
  background: var(--accent-hover);
}
.voice-btn {
  font-size: 1.2rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
}
.voice-btn:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}
.voice-recording {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.voice-recording.hidden { display: none; }
.voice-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  background: #ef4444;
  animation: pulse 1s infinite;
}
#voice-timer {
  font-size: 0.9rem;
  color: var(--text);
  min-width: 3em;
}
.voice-send-btn, .voice-cancel-btn {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.4rem 0.75rem;
  border: none;
  border-radius: 6px;
  cursor: pointer;
}
.voice-send-btn { background: var(--accent); color: white; }
.voice-cancel-btn { background: var(--surface-hover); color: var(--text-muted); }

/* ===== Rules button ===== */
.rules-tab {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 100;
  font-family: 'Unbounded', sans-serif;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.05em;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.2s, border-color 0.2s, background 0.2s;
}
.rules-tab:hover {
  color: var(--text);
  border-color: var(--accent);
  background: var(--surface-hover);
}

/* Rules modal */
.rules-modal {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.rules-modal.hidden {
  display: none;
}
.rules-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  cursor: pointer;
}
.rules-modal-content {
  position: relative;
  max-width: 95vw;
  max-height: 95vh;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}
.rules-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  z-index: 2;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 50%;
  background: rgba(0, 0, 0, 0.6);
  color: white;
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
  transition: background 0.2s;
}
.rules-modal-close:hover {
  background: rgba(0, 0, 0, 0.8);
}
.rules-image {
  display: block;
  max-width: 100%;
  max-height: 90vh;
  width: auto;
  height: auto;
  vertical-align: middle;
}

/* ===== Fullscreen notifications ===== */
.fullscreen-notice {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity 0.5s ease;
  pointer-events: none;
}
.fullscreen-notice.visible {
  opacity: 1;
  pointer-events: all;
}
.fullscreen-notice.banned {
  background: rgba(15, 0, 0, 0.95);
}
.fullscreen-notice.promoted {
  background: rgba(0, 15, 0, 0.92);
}
.fullscreen-notice.demoted {
  background: rgba(15, 10, 0, 0.95);
}
.notice-text {
  font-family: 'Unbounded', sans-serif;
  font-size: clamp(2rem, 8vw, 5rem);
  font-weight: 600;
  text-align: center;
  padding: 2rem;
  animation: noticeShake 0.6s ease-in-out;
}
.fullscreen-notice.banned .notice-text {
  color: #ef4444;
  text-shadow: 0 0 40px rgba(239, 68, 68, 0.6), 0 0 80px rgba(239, 68, 68, 0.3);
}
.fullscreen-notice.promoted .notice-text {
  color: #22c55e;
  text-shadow: 0 0 40px rgba(34, 197, 94, 0.6), 0 0 80px rgba(34, 197, 94, 0.3);
}
.fullscreen-notice.demoted .notice-text {
  color: #f59e0b;
  text-shadow: 0 0 40px rgba(245, 158, 11, 0.6), 0 0 80px rgba(245, 158, 11, 0.3);
}
@keyframes noticeShake {
  0%, 100% { transform: scale(1); }
  15% { transform: scale(1.15) rotate(-2deg); }
  30% { transform: scale(1.1) rotate(2deg); }
  45% { transform: scale(1.12) rotate(-1deg); }
  60% { transform: scale(1.08) rotate(1deg); }
  75% { transform: scale(1.05); }
}

/* ===== Toast notifications ===== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 5000;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-width: 340px;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  box-shadow: var(--shadow);
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  animation: toastIn 0.3s ease-out;
  cursor: pointer;
  transition: opacity 0.3s, transform 0.3s;
}
.toast.hiding {
  opacity: 0;
  transform: translateX(100%);
}
.toast-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.8rem;
  font-weight: 600;
  flex-shrink: 0;
}
.toast-body {
  min-width: 0;
}
.toast-sender {
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--accent);
  margin-bottom: 0.15rem;
}
.toast-text {
  font-size: 0.78rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
@keyframes toastIn {
  from { opacity: 0; transform: translateX(100%); }
  to { opacity: 1; transform: translateX(0); }
}

/* ===== Reply preview ===== */
.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.4rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  font-size: 0.8rem;
  flex-shrink: 0;
}
.reply-preview-content {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.reply-preview-nick {
  color: var(--accent);
  font-weight: 500;
  margin-right: 0.5rem;
}
.reply-preview-text {
  color: var(--text-muted);
}
.reply-cancel {
  font-size: 1.2rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 0 0.25rem;
  flex-shrink: 0;
}
.reply-cancel:hover { color: var(--text); }

/* ===== Quote inside message ===== */
.msg-reply {
  padding: 4px 8px;
  margin-bottom: 4px;
  border-left: 2px solid var(--accent);
  background: rgba(99, 102, 241, 0.08);
  border-radius: 0 4px 4px 0;
  font-size: 0.75rem;
  cursor: pointer;
}
.msg.own .msg-reply {
  border-left-color: rgba(255,255,255,0.5);
  background: rgba(255,255,255,0.1);
}
.msg-reply-nick {
  color: var(--accent);
  font-weight: 500;
  margin-right: 4px;
}
.msg.own .msg-reply-nick { color: rgba(255,255,255,0.85); }
.msg-reply-text {
  color: var(--text-muted);
}
.msg.own .msg-reply-text { color: rgba(255,255,255,0.6); }

/* ===== Reactions ===== */
.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}
.reaction-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  font-size: 0.75rem;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--bg);
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}
.reaction-badge:hover {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.1);
}
.reaction-badge.own {
  border-color: var(--accent);
  background: rgba(99, 102, 241, 0.15);
}
.reaction-count {
  font-size: 0.65rem;
  color: var(--text-muted);
}

/* ===== Message hover actions ===== */
.msg {
  position: relative;
}
.msg-actions-bar {
  position: absolute;
  top: -14px;
  right: 8px;
  display: none;
  gap: 2px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  z-index: 10;
}
.msg:hover .msg-actions-bar { display: flex; }
.msg-action-btn {
  font-size: 0.85rem;
  padding: 2px 6px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.15s, color 0.15s;
  line-height: 1;
}
.msg-action-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ===== Reaction picker (floating) ===== */
.reaction-picker {
  position: fixed;
  z-index: 600;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  box-shadow: var(--shadow);
  padding: 4px 6px;
  display: flex;
  gap: 2px;
}
.rp-emoji {
  font-size: 1.2rem;
  padding: 4px 6px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.rp-emoji:hover { background: var(--surface-hover); transform: scale(1.2); }

/* ===== Emoji picker ===== */
.emoji-picker {
  position: absolute;
  bottom: calc(100% + 4px);
  left: 0;
  width: 320px;
  max-height: 280px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow-y: auto;
  z-index: 500;
  padding: 0.5rem;
}
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 2px;
}
.emoji-grid span {
  font-size: 1.3rem;
  text-align: center;
  padding: 4px;
  border-radius: 6px;
  cursor: pointer;
  transition: background 0.15s;
}
.emoji-grid span:hover { background: var(--surface-hover); }

/* ===== Tool buttons ===== */
.tool-btn {
  font-size: 1.1rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.6rem;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s;
  flex-shrink: 0;
  color: var(--text);
  line-height: 1;
}
.tool-btn:hover {
  border-color: var(--accent);
  background: var(--surface-hover);
}

/* ===== Media in messages ===== */
.msg-media { margin: 0.25rem 0; cursor: pointer; }
.msg-image {
  max-width: 300px;
  max-height: 300px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
  pointer-events: none;
}
.msg-video {
  max-width: 300px;
  max-height: 300px;
  border-radius: 8px;
  display: block;
  cursor: pointer;
}
.msg-media-open { cursor: pointer; }

/* ===== Attach menu (скрепка) ===== */
.attach-wrap {
  position: relative;
  flex-shrink: 0;
}
.attach-menu {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0;
  min-width: 200px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.35rem;
  z-index: 550;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.attach-menu.hidden { display: none !important; }
.attach-menu-item {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border: none;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: background 0.15s;
  white-space: nowrap;
}
.attach-menu-item:hover { background: var(--surface-hover); }

/* ===== Hamburger button (hidden on desktop) ===== */
.menu-btn {
  display: none;
  font-size: 1.4rem;
  background: none;
  border: none;
  color: var(--text);
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  flex-shrink: 0;
}

/* Sidebar backdrop (mobile only) */
.sidebar-backdrop {
  display: none;
}

/* ===== Mobile ===== */
@media (max-width: 768px) {
  body {
    position: fixed;
    width: 100%;
    left: 0;
    right: 0;
  }

  .menu-btn {
    display: none;
  }
  .chat-main.mobile-showing-list .messages,
  .chat-main.mobile-showing-list .reply-preview,
  .chat-main.mobile-showing-list .poll-form,
  .chat-main.mobile-showing-list .send-form,
  .chat-main.mobile-showing-list .voice-recording {
    display: none !important;
  }
  .chat-main.mobile-showing-list .mobile-list-view:not(.hidden) {
    display: block !important;
  }

  #chat {
    grid-template-columns: 1fr;
    grid-template-areas:
      "header"
      "main";
    max-height: 100vh;
    max-height: 100dvh;
    max-height: -webkit-fill-available;
    width: 100%;
    min-width: 0;
  }

  .chat-main {
    padding-bottom: calc(56px + env(safe-area-inset-bottom));
  }

  .chat-header {
    padding-top: max(0.6rem, env(safe-area-inset-top));
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
  }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: 280px;
    z-index: 900;
    transform: translateX(-100%);
    transition: transform 0.3s ease;
    border-right: 1px solid var(--border);
    box-shadow: var(--shadow);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .sidebar-backdrop {
    position: fixed;
    inset: 0;
    z-index: 899;
    background: rgba(0, 0, 0, 0.6);
    transition: opacity 0.3s;
  }
  .sidebar-backdrop.hidden {
    display: none !important;
  }
  .sidebar-backdrop:not(.hidden) {
    display: block;
  }

  .chat-header {
    padding: 0.6rem 0.75rem;
    gap: 0.5rem;
  }

  .chat-header h1 {
    font-size: 0.9rem;
  }

  .chat-header h1 {
    display: none;
  }

  .header-center {
    flex: 1;
    min-width: 0;
    max-width: 50%;
  }

  .call-buttons {
    display: flex;
    gap: 2px;
    flex-shrink: 0;
  }

  .call-header-btn {
    padding: 0.25rem;
    font-size: 1rem;
    background: none;
    border: none;
    cursor: pointer;
    flex-shrink: 0;
    line-height: 1;
  }

  .pin-btn,
  .theme-btn {
    padding: 0.25rem 0.4rem;
    font-size: 1rem;
  }

  .online {
    max-width: 72px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .my-profile-link {
    font-size: 0.6rem;
    padding: 0.25rem 0.35rem;
  }

  .header-back-btn:not(.hidden) {
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .header-discussion-name {
    font-size: 0.8rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .online {
    font-size: 0.75rem;
  }

  .messages {
    padding: 0.75rem;
  }

  .msg {
    max-width: 88%;
    font-size: 0.85rem;
    padding: 0.5rem 0.75rem;
  }

  .msg .nick {
    font-size: 0.7rem;
  }

  .msg .time {
    font-size: 0.65rem;
  }

  .send-form {
    padding: 0.5rem 0.75rem;
    gap: 0.35rem;
  }

  .send-form {
    padding-bottom: max(0.5rem, env(safe-area-inset-bottom));
  }

  .send-form input {
    padding: 0.65rem 0.75rem;
    font-size: 0.85rem;
    min-width: 0;
    max-width: 100%;
  }

  .send-form button[type="submit"] {
    padding: 0.65rem 0.75rem;
    font-size: 0.8rem;
  }

  .voice-btn {
    padding: 0.4rem 0.6rem;
    font-size: 1rem;
  }

  .voice-recording {
    padding: 0.5rem 0.75rem;
  }

  .welcome-card {
    margin: 1rem;
    padding: 1.5rem;
  }

  .rules-tab {
    top: 8px;
    right: 8px;
    font-size: 0.65rem;
    padding: 0.35rem 0.5rem;
  }

  .toast-container {
    top: auto;
    bottom: 5rem;
    right: 0.5rem;
    left: 0.5rem;
    max-width: none;
  }

  .msg-actions-bar { display: none !important; }
  .msg.active-touch .msg-actions-bar { display: flex !important; }

  .emoji-picker {
    position: fixed;
    bottom: 56px;
    left: 0;
    right: 0;
    width: auto;
    max-height: 40vh;
    border-radius: var(--radius) var(--radius) 0 0;
  }

  .reaction-picker {
    bottom: 60px;
    left: 50%;
    transform: translateX(-50%);
  }

  .msg-image, .msg-video { max-width: 200px; max-height: 200px; }

  .reply-preview { padding: 0.3rem 0.75rem; }

  .discussion-item,
  .dm-contact {
    padding: 0.65rem 0.75rem;
    font-size: 0.85rem;
  }

  .sidebar-section-btn {
    padding: 0.9rem 1rem;
    font-size: 0.85rem;
  }
}

@media (max-width: 400px) {
  .send-form button[type="submit"] {
    padding: 0.6rem;
    font-size: 0;
  }
  .send-form button[type="submit"]::after {
    content: "→";
    font-size: 1.1rem;
  }

  .chat-header h1 {
    font-size: 0.8rem;
  }
}

/* ===== Themes ===== */
body.theme-light {
  --bg: #f0f2f5;
  --surface: #ffffff;
  --surface-hover: #f5f5f5;
  --border: #dce0e8;
  --text: #1a1a2e;
  --text-muted: #5c5c7a;
  --accent: #6366f1;
  --accent-hover: #818cf8;
  --system: #22c55e;
  --you: #3b82f6;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}
body.theme-midnight {
  --bg: #0a0e1a;
  --surface: #111827;
  --surface-hover: #1e293b;
  --border: #1e3a5f;
  --text: #e2e8f0;
  --text-muted: #64748b;
  --accent: #3b82f6;
  --accent-hover: #60a5fa;
  --system: #22c55e;
  --you: #6366f1;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}
body.theme-forest {
  --bg: #0a120a;
  --surface: #1a2e1a;
  --surface-hover: #243824;
  --border: #2d4a2d;
  --text: #d4e8d4;
  --text-muted: #7a9e7a;
  --accent: #22c55e;
  --accent-hover: #4ade80;
  --system: #22c55e;
  --you: #16a34a;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.5);
}

/* ===== Theme picker ===== */
.theme-btn {
  font-size: 1.1rem;
  background: none;
  border: none;
  cursor: pointer;
  padding: 0.25rem;
  line-height: 1;
  flex-shrink: 0;
}
.theme-dropdown {
  position: fixed;
  top: 52px;
  right: 120px;
  z-index: 700;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.35rem;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.theme-option {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.5rem 0.75rem;
  border: none;
  background: transparent;
  color: var(--text);
  cursor: pointer;
  border-radius: 8px;
  text-align: left;
  white-space: nowrap;
  transition: background 0.15s;
}
.theme-option:hover { background: var(--surface-hover); }
.theme-option.active { background: var(--accent); color: white; }

/* ===== Pin button & panel ===== */
.pin-btn {
  font-size: 0.85rem;
  background: none;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.3rem 0.6rem;
  cursor: pointer;
  color: var(--text-muted);
  transition: border-color 0.2s;
  flex-shrink: 0;
  line-height: 1;
}
.pin-btn:hover { border-color: var(--accent); color: var(--text); }
.pinned-panel {
  position: fixed;
  top: 52px;
  right: 0;
  width: 360px;
  max-width: 90vw;
  max-height: 60vh;
  z-index: 700;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
}
.pinned-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 1rem;
  border-bottom: 1px solid var(--border);
}
.pinned-panel-header h3 {
  font-size: 0.9rem;
  font-weight: 500;
}
.pinned-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}
.pinned-item {
  padding: 0.5rem 0.75rem;
  border-radius: 8px;
  font-size: 0.8rem;
  border: 1px solid var(--border);
  margin-bottom: 0.35rem;
  cursor: pointer;
  transition: background 0.15s;
}
.pinned-item:hover { background: var(--surface-hover); }
.pinned-item-nick {
  color: var(--accent);
  font-weight: 500;
  font-size: 0.7rem;
}
.pinned-item-text {
  margin-top: 0.2rem;
  color: var(--text);
  word-break: break-word;
}
.pinned-item-unpin {
  float: right;
  font-size: 0.7rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
}
.pinned-item-unpin:hover { color: #ef4444; }
.msg-pinned-indicator {
  font-size: 0.6rem;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 0.2rem;
  margin-bottom: 2px;
}

/* ===== Poll form ===== */
.poll-form {
  padding: 0.75rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.poll-form-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
  font-size: 0.85rem;
  font-weight: 500;
}
.poll-form-input {
  font: inherit;
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  outline: none;
  margin-bottom: 0.35rem;
  font-size: 0.85rem;
}
.poll-form-input:focus { border-color: var(--accent); }
.poll-form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 0.35rem;
}
.btn-ghost {
  font: inherit;
  font-size: 0.8rem;
  padding: 0.35rem 0.6rem;
  border: 1px dashed var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--accent);
  cursor: pointer;
}
.btn-ghost:hover { border-color: var(--accent); background: var(--surface-hover); }

/* ===== Poll in message ===== */
.poll-card {
  margin: 0.25rem 0;
}
.poll-question {
  font-weight: 500;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}
.poll-options { display: flex; flex-direction: column; gap: 0.3rem; }
.poll-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.45rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  font-size: 0.8rem;
  overflow: hidden;
  transition: border-color 0.2s;
  text-align: left;
}
.poll-option:hover { border-color: var(--accent); }
.poll-option.voted { border-color: var(--accent); }
.poll-bar {
  position: absolute;
  left: 0;
  top: 0;
  bottom: 0;
  background: rgba(99, 102, 241, 0.15);
  border-radius: 8px;
  transition: width 0.4s ease;
  pointer-events: none;
}
.poll-option-text { position: relative; z-index: 1; }
.poll-pct { position: relative; z-index: 1; font-size: 0.7rem; color: var(--text-muted); margin-left: auto; padding-left: 0.5rem; }
.poll-total {
  margin-top: 0.6rem;
  padding: 0.5rem 0.75rem;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text);
  background: var(--surface-hover, rgba(99, 102, 241, 0.08));
  border-radius: 8px;
  border-left: 3px solid var(--accent);
}

/* ===== Read receipts ===== */
.read-status {
  font-size: 0.75rem;
  margin-left: 6px;
  letter-spacing: -1px;
  font-weight: 500;
  vertical-align: middle;
}
.read-status:not(.read) {
  color: var(--text-muted);
  opacity: 0.9;
}
.read-status.read {
  color: var(--accent);
}
.msg.own .read-status:not(.read) {
  color: rgba(255,255,255,0.7);
}
.msg.own .read-status.read {
  color: rgba(255,255,255,1);
}

/* ===== Lightbox ===== */
.lightbox {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox.hidden { display: none !important; }
.lightbox-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  cursor: pointer;
}
.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
  width: 48px;
  height: 48px;
  border: none;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.1);
  color: white;
  font-size: 2rem;
  cursor: pointer;
  transition: background 0.2s;
  line-height: 1;
}
.lightbox-close:hover { background: rgba(255, 255, 255, 0.2); }
.lightbox-content {
  position: relative;
  max-width: 95vw;
  max-height: 95vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.lightbox-content img {
  max-width: 95vw;
  max-height: 90vh;
  border-radius: 4px;
  object-fit: contain;
}
.lightbox-content video {
  max-width: 95vw;
  max-height: 90vh;
  border-radius: 4px;
}

/* ===== Pagination loader ===== */
.load-more-bar {
  text-align: center;
  padding: 0.5rem;
  flex-shrink: 0;
}
.load-more-btn {
  font: inherit;
  font-size: 0.75rem;
  padding: 0.35rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--bg);
  color: var(--text-muted);
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}
.load-more-btn:hover { background: var(--surface-hover); color: var(--text); }

/* ===== Create group modal ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.modal-overlay.hidden { display: none !important; }
.modal-overlay-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  cursor: pointer;
}
.modal-overlay-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  width: 100%;
  max-width: 420px;
  max-height: 85vh;
  overflow: auto;
  box-shadow: var(--shadow);
}
.modal-overlay-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.modal-overlay-header h3 { font-size: 1rem; }
.modal-overlay-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.modal-overlay-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1rem;
}

/* Group menu modal */
.group-menu-content .group-menu-members {
  font-size: 0.9rem;
  color: var(--text-muted);
  margin-bottom: 0.5rem;
}
.group-menu-members-list {
  list-style: none;
  margin: 0 0 1rem 0;
  padding: 0;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.35rem;
}
.group-menu-members-list li { margin: 0.25rem 0; }
.group-menu-member-link {
  color: var(--accent);
  text-decoration: none;
  font-size: 0.9rem;
}
.group-menu-member-link:hover { text-decoration: underline; }
.group-menu-avatar-wrap {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.group-menu-avatar-img {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  object-fit: cover;
}
.group-menu-avatar-placeholder {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--surface-hover);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
}
.group-menu-avatar-label {
  font-size: 0.85rem;
  color: var(--accent);
  cursor: pointer;
}
.group-menu-avatar-label:hover { text-decoration: underline; }
.group-menu-name-wrap {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.group-menu-name-wrap input {
  flex: 1;
  min-width: 120px;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
  background: var(--bg);
  color: var(--text);
}
.group-menu-message { margin-top: 0.5rem; }

.group-search-results {
  list-style: none;
  max-height: 160px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 0.5rem;
}
.group-search-item {
  padding: 0.5rem 0.75rem;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
}
.group-search-item:last-child { border-bottom: none; }
.group-search-item:hover { background: var(--surface-hover); }
.group-selected-members {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  margin-top: 0.5rem;
  min-height: 2rem;
}
.group-selected-chip {
  display: inline-flex;
  align-items: center;
  padding: 0.25rem 0.5rem;
  font-size: 0.8rem;
  background: var(--accent);
  color: #fff;
  border-radius: 16px;
  cursor: pointer;
}
.group-selected-chip:hover { opacity: 0.9; }
#new-group-name {
  width: 100%;
  padding: 0.5rem 0.75rem;
  margin-bottom: 0.5rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
#group-member-search {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}

/* ===== Install app banner (mobile) ===== */
.install-banner {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 999;
  padding: 0.75rem 1rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  background: var(--surface);
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 20px rgba(0, 0, 0, 0.3);
}
.install-banner.hidden { display: none !important; }
.install-banner-inner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  max-width: 480px;
  margin: 0 auto;
}
.install-banner-text {
  flex: 1;
  font-size: 0.85rem;
  color: var(--text);
  margin: 0;
  line-height: 1.35;
}
.install-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}
.install-banner-btn {
  font: inherit;
  padding: 0.45rem 0.9rem;
  border-radius: 8px;
  cursor: pointer;
  border: none;
  transition: background 0.2s, color 0.2s;
}
.install-banner-add {
  background: var(--accent);
  color: #fff;
}
.install-banner-add:hover { background: var(--accent-hover); }
.install-banner-close {
  background: transparent;
  color: var(--text-muted);
  font-size: 1.25rem;
  padding: 0.25rem 0.5rem;
}
  .install-banner-close:hover { color: var(--text); }

@media (max-width: 768px) {
  .lightbox-close { width: 40px; height: 40px; font-size: 1.5rem; top: 8px; right: 8px; }
  .pinned-panel { width: 100%; max-width: 100vw; top: 48px; right: 0; left: 0; }
  .theme-dropdown { right: 8px; top: 48px; }
  .poll-form { padding: 0.5rem 0.75rem; }
  .install-banner { padding-bottom: max(0.75rem, env(safe-area-inset-bottom)); }
  .call-buttons { min-width: 0; }
}
