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

:root {
  --bg:          #0f1117;
  --bg2:         #1a1d27;
  --bg3:         #232634;
  --surface:     #2a2d3e;
  --surface2:    #323548;
  --border:      #3a3d52;
  --accent:      #5865f2;
  --accent2:     #4752c4;
  --success:     #43b581;
  --danger:      #ed4245;
  --warning:     #faa61a;
  --text:        #e0e0e8;
  --text2:       #9a9cb0;
  --text3:       #6b6e88;
  --msg-own:     #2d4a8a;
  --msg-other:   #2a2d3e;
  --radius:      12px;
  --radius-sm:   8px;
  --sidebar-w:   300px;
  --transition:  0.18s ease;
}

html, body { height: 100%; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; }
body { background: var(--bg); color: var(--text); overflow: hidden; }

/* ── Layout ── */
body:not(.login-page):not(.admin-page) {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  height: 100vh;
}

.sidebar-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-info { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; }
.user-details { min-width: 0; }
.username { font-weight: 600; font-size: 0.9rem; text-overflow: ellipsis; white-space: nowrap; overflow: hidden; }

.sidebar-actions { display: flex; gap: 4px; flex-shrink: 0; }

.search-bar { padding: 10px 12px; }
.search-bar input {
  width: 100%;
  padding: 8px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text);
  font-size: 0.85rem;
  outline: none;
}
.search-bar input:focus { border-color: var(--accent); }

.group-list { flex: 1; overflow-y: auto; }

.group-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  cursor: pointer;
  border-radius: 0;
  transition: background var(--transition);
  border-bottom: 1px solid transparent;
}
.group-item:hover { background: var(--bg3); }
.group-item.active { background: var(--surface); }

.group-item-info { flex: 1; min-width: 0; }
.group-item-name {
  font-size: 0.9rem;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.group-item-last {
  font-size: 0.78rem;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}
.group-item-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  flex-shrink: 0;
}
.group-time { font-size: 0.7rem; color: var(--text3); }
.unread-badge {
  background: var(--accent);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
  border-radius: 10px;
  padding: 1px 7px;
  min-width: 18px;
  text-align: center;
}

.loading-groups { color: var(--text3); font-size: 0.85rem; padding: 20px; text-align: center; }

/* ── Sidebar tabs ── */
.sidebar-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.stab {
  flex: 1;
  text-align: center;
  padding: 9px 4px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text3);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all var(--transition);
}
.stab:hover { color: var(--text2); }
.stab.active { color: var(--accent); border-bottom-color: var(--accent); }
.stab-badge {
  display: inline-block;
  background: var(--danger, #e74c3c);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
  padding: 2px 5px;
  border-radius: 8px;
  margin-left: 5px;
  vertical-align: middle;
  min-width: 16px;
  text-align: center;
}
.stab-badge:empty { display: none; }

/* ── DM avatar (letter, not emoji) ── */
.group-avatar.dm-avatar {
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
  font-weight: 700;
}

/* ── Presence dot ── */
.presence-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.presence-dot.online  { background: var(--success); }
.presence-dot.offline { background: var(--text3); }

/* ── Chat area ── */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  background: var(--bg);
}

.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text3);
}
.empty-icon { font-size: 4rem; }
.empty-title { font-size: 1.1rem; font-weight: 600; color: var(--text2); }
.empty-sub { font-size: 0.85rem; }

.chat-header {
  padding: 12px 16px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  flex-shrink: 0;
}
.chat-header-avatar { font-size: 1.4rem; }
.chat-header-info { flex: 1; }
.chat-header-name { font-weight: 700; font-size: 0.95rem; }
.chat-header-sub { font-size: 0.78rem; color: var(--text2); }
.chat-header-actions { display: flex; gap: 4px; }
.back-btn { display: none; background: none; border: none; color: var(--text); font-size: 1.2rem; cursor: pointer; padding: 4px 8px; }

/* ── Topic bar ── */
.topic-bar {
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 6px 10px;
  gap: 6px;
  flex-shrink: 0;
  overflow-x: auto;
}
.topic-tabs { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.topic-tab {
  display: flex;
  align-items: center;
  gap: 3px;
  padding: 5px 10px;
  border-radius: 16px;
  cursor: pointer;
  font-size: 0.82rem;
  background: var(--bg3);
  border: 1px solid transparent;
  color: var(--text2);
  transition: all var(--transition);
  max-width: 130px;
  flex-shrink: 0;
  overflow: hidden;
}
.topic-tab .tab-label {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  min-width: 0;
  flex: 1;
}
.topic-tab:hover { background: var(--surface); color: var(--text); }
.topic-tab.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.topic-unread-badge {
  display: inline-block;
  background: #e74c3c;
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  border-radius: 8px;
  padding: 1px 5px;
  line-height: 1.4;
  flex-shrink: 0;
}
.topic-tab.active .topic-unread-badge { background: rgba(255,255,255,0.35); color: #fff; }

/* ── Topic label on message ── */
.msg-topic-badge {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  background: rgba(88, 101, 242, 0.15);
  border: 1px solid rgba(88, 101, 242, 0.3);
  color: #7289da;
  font-size: 0.68rem;
  border-radius: 6px;
  padding: 1px 6px;
  margin-right: 6px;
  vertical-align: middle;
  white-space: nowrap;
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Messages ── */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.load-more {
  text-align: center;
  padding: 8px;
  color: var(--accent);
  cursor: pointer;
  font-size: 0.85rem;
  border-radius: 20px;
  border: 1px solid var(--border);
  margin-bottom: 8px;
}
.load-more:hover { background: var(--bg3); }

.date-separator {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text3);
  padding: 8px 0;
  position: relative;
}
.date-separator::before, .date-separator::after {
  content: '';
  position: absolute;
  top: 50%;
  width: 40%;
  height: 1px;
  background: var(--border);
}
.date-separator::before { left: 0; }
.date-separator::after { right: 0; }

.msg-group { display: flex; flex-direction: column; gap: 2px; margin-bottom: 6px; }

.msg-bubble-wrap {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 2px 12px;
  position: relative;
}
.msg-bubble-wrap.grouped { padding-top: 1px; }
.msg-bubble-wrap.own { flex-direction: row-reverse; }
/* Hover toolbar visible on wrap hover */
.msg-bubble-wrap:hover .msg-toolbar { opacity: 1; pointer-events: all; }

.msg-avatar { width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0; }
.msg-avatar.placeholder { width: 32px; height: 32px; flex-shrink: 0; }

.msg-content { max-width: 65%; display: flex; flex-direction: column; }
.msg-bubble-wrap.own .msg-content { align-items: flex-end; }

.msg-sender {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent);
  margin-bottom: 2px;
  padding: 0 4px;
}

.msg-bubble {
  background: var(--msg-other);
  border-radius: var(--radius);
  border-bottom-left-radius: 4px;
  padding: 8px 12px;
  font-size: 0.875rem;
  line-height: 1.5;
  word-wrap: break-word;
  position: relative;
  cursor: pointer;
  transition: background var(--transition);
}
.msg-bubble-wrap.own .msg-bubble {
  background: var(--msg-own);
  border-bottom-left-radius: var(--radius);
  border-bottom-right-radius: 4px;
}
.msg-bubble:hover { filter: brightness(1.1); }

.msg-reply-preview {
  background: rgba(255,255,255,0.07);
  border-left: 3px solid var(--accent);
  padding: 4px 8px;
  border-radius: 4px;
  margin-bottom: 6px;
  font-size: 0.78rem;
  cursor: pointer;
  transition: background .15s;
}
.msg-reply-preview:hover { background: rgba(99,102,241,0.18); }
.msg-reply-preview .reply-sender { font-weight: 600; color: var(--accent); }
.msg-reply-preview .reply-text { color: var(--text2); }

@keyframes msgHighlight {
  0%   { background: rgba(99,102,241,0.35); }
  60%  { background: rgba(99,102,241,0.22); }
  100% { background: transparent; }
}
.msg-highlight > .msg-content > .msg-bubble {
  animation: msgHighlight 1.8s ease-out forwards;
  border-radius: 10px;
}

.msg-text { white-space: pre-wrap; }
.msg-deleted { color: var(--text3); font-style: italic; }

.msg-image {
  max-width: 280px;
  border-radius: 8px;
  cursor: pointer;
  display: block;
}

.msg-file {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 0;
}
.msg-file-icon { font-size: 1.5rem; }
.msg-file-info { flex: 1; }
.msg-file-name { font-size: 0.85rem; font-weight: 600; }
.msg-file-size { font-size: 0.75rem; color: var(--text2); }
.msg-file a { color: var(--accent); text-decoration: none; font-size: 0.8rem; }

.msg-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.7rem;
  color: var(--text3);
  padding: 2px 4px;
  margin-top: 2px;
}
.msg-bubble-wrap.own .msg-meta { justify-content: flex-end; }
.msg-edited { font-style: italic; }

.msg-reactions {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
  padding: 0 4px;
}
.reaction-pill {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2px 8px;
  font-size: 0.8rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 3px;
  transition: background var(--transition);
}
.reaction-pill:hover, .reaction-pill.mine { background: var(--surface2); border-color: var(--accent); }

.system-msg {
  text-align: center;
  font-size: 0.78rem;
  color: var(--text3);
  padding: 4px 0;
}

/* ── Typing dots ── */
.typing-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 16px;
  min-height: 28px;
  font-size: 0.78rem;
  color: var(--text3);
  font-style: italic;
}
.typing-dots { display: flex; gap: 3px; align-items: center; }
.typing-dots span {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text3);
  animation: typingBounce 1.2s infinite ease-in-out;
}
.typing-dots span:nth-child(2) { animation-delay: .2s; }
.typing-dots span:nth-child(3) { animation-delay: .4s; }
@keyframes typingBounce {
  0%, 60%, 100% { transform: translateY(0);   opacity: .4; }
  30%            { transform: translateY(-5px); opacity: 1;  }
}

/* ── Hover Toolbar ── */
.msg-toolbar {
  position: absolute;
  top: -18px;
  right: 52px;
  display: flex;
  gap: 2px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 3px 6px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .15s ease;
  z-index: 10;
  box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
.msg-bubble-wrap.own .msg-toolbar { right: auto; left: 52px; }
.tb-btn {
  background: none; border: none; cursor: pointer;
  font-size: 0.9rem; padding: 2px 5px; border-radius: 12px;
  color: var(--text2); transition: background .12s;
  line-height: 1;
}
.tb-btn:hover     { background: var(--surface2); }
.tb-btn.tb-del:hover { background: rgba(237,66,69,.2); }

/* ── Scroll-to-bottom button ── */
.scroll-bottom-btn {
  position: absolute;
  bottom: 80px;
  right: 20px;
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--bg2);
  border: 1px solid var(--border);
  color: var(--text);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 2px 10px rgba(0,0,0,.4);
  z-index: 50;
  transition: background var(--transition);
}
.scroll-bottom-btn:hover { background: var(--surface); }
.scroll-bottom-arrow { font-size: 1.1rem; line-height: 1; }
.scroll-bottom-badge {
  position: absolute;
  top: -6px; right: -4px;
  background: var(--accent);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 4px;
}

/* ── Edit banner ── */
.edit-banner {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 14px;
  background: rgba(88,101,242,.1);
  border-left: 3px solid var(--accent);
  border-radius: 0;
}
.edit-banner-icon { font-size: 1rem; flex-shrink: 0; }
.edit-banner-body { flex: 1; min-width: 0; }
.edit-banner-label { font-size: 0.72rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .04em; }
.edit-banner-preview { font-size: 0.8rem; color: var(--text2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.edit-banner button { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 0.9rem; }
.edit-banner button:hover { color: var(--text); }

/* Edit mode input */
#msg-input.editing-mode { border-color: var(--accent); }
.send-btn-edit { background: var(--success) !important; }

/* Grouped message tweaks */
.msg-bubble-wrap.grouped .msg-bubble { border-radius: var(--radius); }
.msg-bubble-wrap.grouped.own .msg-bubble { border-radius: var(--radius); }
.msg-sender-spacer { height: 0; }

/* Remove old padding from #messages since wrap handles it */
#message-list { padding: 8px 0; }

/* ── Input area ── */
.chat-input-area {
  background: var(--bg2);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  flex-shrink: 0;
}

.reply-preview {
  background: var(--bg3);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
  padding: 6px 10px;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 0.82rem;
}
.reply-name { font-weight: 700; color: var(--accent); margin-right: 6px; }
.reply-text { color: var(--text2); }
.reply-preview button { background: none; border: none; color: var(--text3); cursor: pointer; font-size: 1rem; }

.input-row { display: flex; align-items: flex-end; gap: 8px; }

.attach-btn {
  color: var(--text2);
  cursor: pointer;
  font-size: 1.3rem;
  padding: 6px;
  border-radius: 50%;
  flex-shrink: 0;
  line-height: 1;
  transition: color var(--transition);
}
.attach-btn:hover { color: var(--accent); }

.input-wrapper { flex: 1; position: relative; }

.file-preview-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  padding: 6px 0;
}
.file-preview-item {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px 10px;
  font-size: 0.78rem;
  display: flex;
  align-items: center;
  gap: 6px;
}
.file-preview-item button {
  background: none; border: none; color: var(--text3); cursor: pointer; font-size: 0.9rem;
}

textarea#msg-input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 0.9rem;
  resize: none;
  outline: none;
  min-height: 40px;
  max-height: 160px;
  line-height: 1.4;
  font-family: inherit;
  transition: border-color var(--transition);
}
textarea#msg-input:focus { border-color: var(--accent); }
textarea#msg-input::placeholder { color: var(--text3); }

.send-btn {
  background: var(--accent);
  border: none;
  color: #fff;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 1.1rem;
  flex-shrink: 0;
  transition: background var(--transition);
  display: flex;
  align-items: center;
  justify-content: center;
}
.send-btn:hover { background: var(--accent2); }

.emoji-bar {
  display: flex;
  gap: 8px;
  padding: 6px 2px 2px;
  font-size: 1.2rem;
}
.emoji-bar span { cursor: pointer; transition: transform 0.1s; }
.emoji-bar span:hover { transform: scale(1.3); }

/* ── Avatars ── */
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 1rem;
  color: #fff;
  flex-shrink: 0;
}
.avatar.sm { width: 28px; height: 28px; font-size: 0.75rem; }
.avatar.lg { width: 52px; height: 52px; font-size: 1.3rem; }

.group-avatar {
  width: 44px; height: 44px;
  border-radius: 50%;
  background: var(--surface2);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}
.msg-avatar-circle {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--accent);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

/* ── Role badges ── */
.role-badge {
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  padding: 2px 7px;
  border-radius: 8px;
  letter-spacing: 0.05em;
  display: inline-block;
}
.role-manager  { background: rgba(237,66,69,.2);  color: #ed4245; }
.role-leader   { background: rgba(250,166,26,.2); color: #faa61a; }
.role-employee { background: rgba(88,101,242,.2); color: #5865f2; }
.role-disabled { background: rgba(150,150,150,.2); color: #888; }

/* ── Buttons ── */
.icon-btn {
  background: none; border: none;
  color: var(--text2); cursor: pointer;
  font-size: 1rem;
  width: 32px; height: 32px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  transition: background var(--transition), color var(--transition);
}
.icon-btn:hover { background: var(--bg3); color: var(--text); }

.btn-primary {
  background: var(--accent);
  color: #fff; border: none;
  padding: 8px 18px; border-radius: 8px;
  cursor: pointer; font-size: 0.875rem; font-weight: 600;
  transition: background var(--transition);
}
.btn-primary:hover { background: var(--accent2); }

.btn-secondary {
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  padding: 7px 16px; border-radius: 8px;
  cursor: pointer; font-size: 0.875rem;
  transition: background var(--transition);
}
.btn-secondary:hover { background: var(--surface2); }

.btn-cancel {
  background: none; color: var(--text2);
  border: 1px solid var(--border);
  padding: 8px 16px; border-radius: 8px;
  cursor: pointer; font-size: 0.875rem;
  transition: background var(--transition);
}
.btn-cancel:hover { background: var(--bg3); }

.btn-sm {
  padding: 4px 10px; border-radius: 6px;
  font-size: 0.78rem; cursor: pointer;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border);
  transition: background var(--transition);
}
.btn-sm:hover { background: var(--surface2); }
.btn-sm.btn-danger { color: var(--danger); border-color: var(--danger); }
.btn-sm.btn-danger:hover { background: rgba(237,66,69,.15); }

/* ── Modals ── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 16px;
}
.modal {
  background: var(--bg2);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  width: 100%; max-width: 480px;
  max-height: 90vh;
  display: flex; flex-direction: column;
  overflow: hidden;
}
.modal.modal-sm { max-width: 360px; }
.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-header h3 { font-size: 1rem; }
.modal-header button {
  background: none; border: none; color: var(--text2);
  font-size: 1.1rem; cursor: pointer;
}
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 8px;
}

.form-group { margin-bottom: 14px; }
.form-group label { display: block; font-size: 0.8rem; color: var(--text2); margin-bottom: 6px; }
.form-group input, .form-group select, .form-group textarea {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-size: 0.875rem;
  outline: none;
  transition: border-color var(--transition);
  font-family: inherit;
}
.form-group input:focus, .form-group select:focus { border-color: var(--accent); }
.form-group select option { background: var(--bg2); }

.form-error {
  background: rgba(237,66,69,.15);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 8px 12px;
  font-size: 0.82rem;
  color: var(--danger);
  margin-top: 8px;
}

/* ── Member picker ── */
.member-picker {
  max-height: 320px;
  overflow-y: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg3);
}
.member-pick-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}
.member-pick-item:last-child { border-bottom: none; }
.member-pick-item:hover { background: var(--surface); }
.member-pick-item.selected { background: rgba(88,101,242,.15); }
#member-picker-selected { background: rgba(88,101,242,.08); border-radius: var(--radius-sm) var(--radius-sm) 0 0; }
#member-picker-selected .member-pick-item.selected:hover { background: rgba(220,50,50,.12); }

/* ── Context menu ── */
.context-menu {
  position: fixed;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  min-width: 160px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  z-index: 2000;
  overflow: hidden;
}
.ctx-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.875rem;
  transition: background var(--transition);
}
.ctx-item:hover { background: var(--bg3); }
.ctx-item.ctx-delete { color: var(--danger); }
.ctx-item.ctx-reactions { display: flex; gap: 8px; font-size: 1.2rem; padding: 8px 14px; }

/* ── Lightbox ── */
.lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center;
  z-index: 3000; cursor: zoom-out;
}
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 8px; }

/* ── Login page ── */
.login-page {
  display: flex; align-items: center; justify-content: center;
  min-height: 100vh; overflow: auto;
  background: radial-gradient(ellipse at 50% 0%, rgba(88,101,242,.2) 0%, var(--bg) 70%);
}
.login-container {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%; max-width: 380px;
  text-align: center;
}
.login-logo { font-size: 3rem; margin-bottom: 12px; }
.login-title { font-size: 1.4rem; font-weight: 700; margin-bottom: 4px; }
.login-sub { font-size: 0.82rem; color: var(--text2); margin-bottom: 28px; }
.login-error {
  background: rgba(237,66,69,.15);
  border: 1px solid var(--danger);
  border-radius: 8px;
  padding: 10px;
  color: var(--danger);
  font-size: 0.85rem;
  margin-bottom: 16px;
}
.login-container .form-group { text-align: left; }
.login-container input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 16px;
  color: var(--text);
  font-size: 0.9rem;
  outline: none;
  margin-bottom: 12px;
  transition: border-color var(--transition);
  font-family: inherit;
}
.login-container input:focus { border-color: var(--accent); }
.btn-login {
  width: 100%;
  background: var(--accent);
  color: #fff; border: none;
  padding: 12px; border-radius: 10px;
  cursor: pointer; font-size: 0.95rem; font-weight: 600;
  transition: background var(--transition);
  margin-top: 4px;
}
.btn-login:hover { background: var(--accent2); }
.login-footer { margin-top: 20px; font-size: 0.78rem; color: var(--text3); }

/* ── Admin page ── */
.admin-page { display: block; min-height: 100vh; overflow: auto; background: var(--bg); }
.admin-container { max-width: 900px; margin: 0 auto; padding: 24px 16px; }
.admin-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 24px;
}
.admin-title h2 { font-size: 1.2rem; }
.back-link { font-size: 0.85rem; color: var(--accent); text-decoration: none; display: block; margin-bottom: 4px; }
.back-link:hover { text-decoration: underline; }

.admin-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
}
.card-title { font-size: 0.9rem; font-weight: 700; color: var(--text2); margin-bottom: 14px; text-transform: uppercase; letter-spacing: 0.05em; }

.admin-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.admin-table th { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); color: var(--text2); font-weight: 600; font-size: 0.78rem; text-transform: uppercase; }
.admin-table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.admin-table tr:last-child td { border-bottom: none; }
.admin-table tr:hover td { background: var(--bg3); }
.disabled-row td { opacity: 0.5; }

.user-cell { display: flex; align-items: center; gap: 8px; }
.muted { color: var(--text2); font-size: 0.8rem; }
.you-badge {
  background: var(--bg3); border-radius: 4px;
  padding: 1px 5px; font-size: 0.65rem; color: var(--text3);
}
.action-btns { display: flex; gap: 6px; }

/* ── Toast ── */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 20px;
  font-size: 0.875rem;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,.4);
}

/* ── Reload banner ── */
#reload-banner {
  position: fixed; top: 0; left: 0; right: 0;
  background: var(--accent); color: #fff;
  text-align: center; padding: 10px 16px;
  font-size: 0.9rem; z-index: 99999;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}
#reload-banner button {
  margin-left: 12px; padding: 4px 14px;
  background: #fff; color: var(--accent);
  border: none; border-radius: 6px;
  font-weight: 600; cursor: pointer;
}
#reload-banner button:hover { background: #e8e8ff; }

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--surface2); }

/* ── IT Tasks ── */
.modal-it {
  width: 560px;
  max-width: 96vw;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
}
.modal-it .modal-body {
  overflow-y: auto;
  padding: 0;
}
.modal-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}
.btn-sm-inline {
  padding: 5px 12px;
  font-size: 0.8rem;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
.btn-sm-inline:hover { background: var(--accent2); }

.it-tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  padding: 0 16px;
  background: var(--bg2);
}
.it-tab {
  padding: 10px 16px;
  cursor: pointer;
  color: var(--text2);
  font-size: 0.875rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.it-tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.it-task-list {
  padding: 12px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.it-empty {
  text-align: center;
  color: var(--text3);
  padding: 32px;
  font-size: 0.9rem;
}
.it-task-card {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  cursor: pointer;
  transition: border-color var(--transition);
}
.it-task-card:hover { border-color: var(--accent); }
.it-task-top {
  display: flex;
  align-items: flex-start;
  gap: 8px;
}
.it-priority { font-size: 1rem; flex-shrink: 0; margin-top: 1px; }
.it-task-title {
  flex: 1;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--text);
  word-break: break-word;
}
.it-task-creator {
  font-size: 0.8rem;
  color: var(--text2);
  padding-left: 22px;
}
.it-task-creator strong { color: var(--text); }
.it-note {
  font-size: 0.8rem;
  color: var(--success);
  padding-left: 22px;
  font-style: italic;
}
.it-task-meta {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  padding-left: 22px;
  margin-top: 2px;
}
.it-meta-item {
  font-size: 0.75rem;
  color: var(--text3);
}
.it-task-actions { margin-left: auto; }
.it-status {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  flex-shrink: 0;
  white-space: nowrap;
}
.it-status.open     { background: rgba(88,101,242,.2); color: var(--accent); }
.it-status.accepted { background: rgba(250,166,26,.2); color: var(--warning); }
.it-status.done     { background: rgba(67,181,129,.2); color: var(--success); }

.it-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  padding: 4px 12px;
  border-radius: 5px;
  cursor: pointer;
  font-size: 0.78rem;
}
.it-btn:hover { background: var(--accent2); }
.it-btn.it-btn-done   { background: var(--success); }
.it-btn.it-btn-done:hover { background: #37a06e; }
.it-btn.it-btn-detail { background: var(--surface2); color: var(--text2); }
.it-btn.it-btn-detail:hover { background: var(--border); color: var(--text); }

.role-badge.role-it     { background: rgba(67,181,129,.15); color: #43b581; }
.role-badge.role-vendor { background: rgba(250,166,26,.15); color: #faa61a; }
.role-badge.role-fanyi  { background: rgba(235,69,158,.2);  color: #eb459e; }
.role-badge.role-pbn     { background: rgba(114,137,218,.2); color: #7289da; }
.role-badge.role-support { background: rgba(32,178,170,.2);  color: #20b2aa; }

/* ── Notification System ── */
.notif-stack {
  position: fixed;
  bottom: 24px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
  max-width: 320px;
  width: 320px;
}
.notif-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 14px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  pointer-events: all;
  box-shadow: 0 8px 24px rgba(0,0,0,.5);
  opacity: 0;
  transform: translateX(120%);
  transition: opacity .25s ease, transform .25s ease;
  border-left: 3px solid var(--accent);
}
.notif-card.notif-mention { border-left-color: var(--warning); }
.notif-card.notif-show    { opacity: 1; transform: translateX(0); }
.notif-card.notif-hide    { opacity: 0; transform: translateX(120%); }
.notif-avatar {
  width: 38px; height: 38px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; font-weight: 700; flex-shrink: 0;
}
.notif-mention .notif-avatar { background: var(--warning); }
.notif-body { flex: 1; min-width: 0; }
.notif-title {
  font-size: 0.82rem; font-weight: 700; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  display: flex; align-items: center; gap: 6px;
}
.notif-mention-badge {
  font-size: 0.68rem; background: var(--warning);
  color: #000; padding: 1px 6px; border-radius: 20px; font-weight: 700;
}
.notif-sender {
  font-size: 0.75rem; color: var(--text2); margin: 1px 0 2px;
}
.notif-preview {
  font-size: 0.78rem; color: var(--text3);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.notif-close {
  background: none; border: none; color: var(--text3);
  cursor: pointer; padding: 2px 4px; font-size: 0.8rem;
  flex-shrink: 0; align-self: flex-start;
}
.notif-close:hover { color: var(--text); }

/* @mention picker dropdown */
.mention-picker {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 0; right: 0;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: 0 -4px 20px rgba(0,0,0,.4);
  z-index: 500;
  max-height: 220px;
  overflow-y: auto;
}
.mention-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  cursor: pointer;
  transition: background var(--transition);
}
.mention-item:hover, .mention-item.active { background: var(--bg3); }
.mention-item-avatar {
  width: 28px; height: 28px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 0.8rem; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.mention-item-name  { font-size: 0.875rem; font-weight: 600; flex: 1; }
.mention-item-role  { font-size: 0.75rem; color: var(--text3); }

/* @mention highlights */
.mention    { color: var(--accent); font-weight: 600; }
.mention-me {
  color: var(--warning); font-weight: 700;
  background: rgba(250,166,26,.12);
  border-radius: 4px; padding: 0 3px;
}

/* ── Settings Panel ── */
.user-info-clickable { cursor: pointer; border-radius: var(--radius-sm); padding: 4px 6px; margin: -4px -6px; transition: background var(--transition); }
.user-info-clickable:hover { background: var(--surface); }

.settings-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.45); z-index: 200;
}
.settings-panel {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: 340px; max-width: 100vw;
  background: var(--bg2);
  border-right: 1px solid var(--border);
  z-index: 201;
  display: flex;
  flex-direction: column;
  animation: slideInLeft .2s ease;
}
@keyframes slideInLeft {
  from { transform: translateX(-100%); }
  to   { transform: translateX(0); }
}
.settings-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  font-size: 1rem; font-weight: 600;
}
.settings-body {
  overflow-y: auto;
  flex: 1;
  padding: 0 0 24px;
}
.settings-section {
  padding: 20px 20px 0;
  border-bottom: 1px solid var(--border);
  padding-bottom: 20px;
  margin-bottom: 0;
}
.settings-section + .settings-section { padding-top: 20px; }
.settings-section-title {
  font-size: 0.7rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text3); margin-bottom: 14px;
}
.settings-avatar-row {
  display: flex; align-items: center; gap: 14px; margin-bottom: 16px;
}
.avatar.lg { width: 52px; height: 52px; font-size: 1.4rem; border-radius: 50%; flex-shrink: 0; }
.settings-avatar-emojis {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.avatar-emoji-opt {
  font-size: 1.3rem; cursor: pointer; padding: 3px 4px; border-radius: 6px;
  border: 2px solid transparent; transition: border-color var(--transition);
  line-height: 1;
}
.avatar-emoji-opt:hover  { border-color: var(--border); }
.avatar-emoji-opt.selected { border-color: var(--accent); }

.form-hint { font-size: 0.72rem; color: var(--text3); font-weight: 400; }
.settings-save-btn { width: 100%; margin-top: 12px; }

.settings-info { }
.settings-info-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.85rem; padding: 6px 0;
  color: var(--text2);
}
.settings-info-row strong { color: var(--text); }

.settings-notif-row {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.85rem; padding: 6px 0; color: var(--text2);
}
.settings-notif-hint {
  font-size: 0.78rem; color: var(--text2); margin-top: 4px; line-height: 1.4;
}
.toggle-btn {
  background: var(--accent); color: #fff; border: none; border-radius: 20px;
  padding: 4px 14px; font-size: 0.8rem; cursor: pointer; transition: background 0.2s;
}
.toggle-btn:hover { background: var(--accent-hover, #1a6fb5); }
.toggle-btn.toggle-btn-off { background: var(--border); color: var(--text2); }
.toggle-btn:disabled { opacity: 0.6; cursor: default; }

/* IT Task Detail */
.it-detail-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.85rem;
  padding: 16px;
  display: block;
}
.it-detail-table tr + tr td { border-top: 1px solid var(--border); }
.it-detail-table td { padding: 8px 12px; vertical-align: top; }
.it-detail-label { color: var(--text3); width: 110px; white-space: nowrap; }
.it-detail-section { padding: 0 16px 16px; }
.it-detail-section-title { font-size: 0.75rem; color: var(--text3); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 6px; }
.it-detail-desc { font-size: 0.85rem; color: var(--text2); white-space: pre-wrap; word-break: break-word; line-height: 1.5; }

/* ── Group Settings Panel ── */
.gs-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  z-index: 200;
  animation: fadeIn .2s ease;
}
.gs-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 320px;
  background: var(--bg2);
  z-index: 201;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transform: translateX(100%);
  transition: transform .25s cubic-bezier(.4,0,.2,1);
  box-shadow: -4px 0 24px rgba(0,0,0,.35);
}
.gs-panel.gs-open { transform: translateX(0); }
.gs-header {
  background: var(--bg3);
  padding: 20px 16px 18px;
  text-align: center;
  position: relative;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.gs-close-btn {
  position: absolute; top: 12px; left: 12px;
  background: none; border: none;
  color: var(--text2); font-size: 1rem;
  cursor: pointer; padding: 4px 8px; border-radius: 4px;
  transition: background .15s;
}
.gs-close-btn:hover { background: var(--hover); color: var(--text); }
.gs-hdr-avatar { font-size: 3.2rem; margin-bottom: 8px; display: block; }
.gs-hdr-name { font-weight: 700; font-size: 1.1rem; color: var(--text); }
.gs-hdr-desc { font-size: .82rem; color: var(--text2); margin-top: 4px; min-height: 1em; }
.gs-section {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.gs-section-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 10px;
}
.gs-section-title {
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .06em;
  color: var(--text3);
}
.gs-add-btn {
  background: none; border: 1px solid var(--accent);
  color: var(--accent); border-radius: 4px;
  padding: 2px 8px; font-size: .78rem;
  cursor: pointer; transition: background .15s;
}
.gs-add-btn:hover { background: var(--accent); color: #fff; }
.gs-save-btn {
  width: 100%; padding: 9px; margin-top: 8px;
  background: var(--accent); color: #fff; border: none;
  border-radius: 6px; cursor: pointer; font-weight: 600;
  font-size: .9rem; transition: opacity .15s;
}
.gs-save-btn:hover { opacity: .88; }
.gs-danger-zone { background: rgba(237,66,69,.04); }
.gs-danger-btn { width: 100%; padding: 8px; font-size: .88rem; }
.gs-avatar-row {
  display: flex; align-items: flex-start; gap: 12px; margin-bottom: 10px;
}
.gs-big-avatar {
  font-size: 2.2rem; width: 52px; height: 52px; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg3); border-radius: 50%;
  border: 2px solid var(--border);
}
.gs-emoji-opts {
  display: flex; flex-wrap: wrap; gap: 4px; align-content: flex-start;
}
.gs-emoji-opt {
  font-size: 1.35rem; cursor: pointer; padding: 3px;
  border-radius: 5px; transition: background .12s;
  line-height: 1;
}
.gs-emoji-opt:hover, .gs-emoji-opt.gs-sel { background: var(--hover); }
/* Topics list in GS panel */
.gs-topic-item {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 6px; border-radius: 6px;
  cursor: pointer; transition: background .12s;
}
.gs-topic-item:hover { background: var(--hover); }
.gs-topic-icon { font-size: 1.1rem; flex-shrink: 0; }
.gs-topic-name { flex: 1; font-size: .9rem; color: var(--text); }
.gs-topic-close {
  background: none; border: none; color: var(--text3);
  font-size: .8rem; cursor: pointer; padding: 2px 5px;
  border-radius: 3px; opacity: 0; transition: opacity .15s, color .15s;
}
.gs-topic-item:hover .gs-topic-close { opacity: 1; }
.gs-topic-close:hover { color: var(--danger); }
.gs-topic-actions {
  display: flex; align-items: center; gap: 2px; flex-shrink: 0;
}
.gs-topic-reorder {
  background: none; border: none; color: var(--text3);
  font-size: .85rem; cursor: pointer; padding: 1px 4px;
  border-radius: 3px; opacity: 0; transition: opacity .15s, color .15s, background .1s;
  line-height: 1;
}
.gs-topic-item:hover .gs-topic-reorder { opacity: 1; }
.gs-topic-reorder:hover { color: var(--accent); background: var(--hover2, rgba(99,102,241,.15)); }
.gs-topic-reorder-placeholder { display: inline-block; width: 22px; }
/* Members list in GS panel */
.gs-member-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 6px; border-radius: 6px;
  transition: background .12s;
}
.gs-member-item:hover { background: var(--hover); }
.gs-member-info { flex: 1; min-width: 0; }
.gs-member-name {
  font-size: .88rem; font-weight: 500; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.gs-member-status { font-size: .72rem; margin-top: 1px; }
.gs-member-status.gs-online  { color: #43b581; }
.gs-member-status.gs-offline { color: var(--text3); }
.gs-remove-btn {
  background: none; border: none; color: var(--text3);
  font-size: .8rem; cursor: pointer; padding: 2px 5px;
  border-radius: 3px; opacity: 0; transition: opacity .15s, color .15s;
}
.gs-member-item:hover .gs-remove-btn { opacity: 1; }
.gs-remove-btn:hover { color: var(--danger); }

/* ── Mobile ── */
@media (max-width: 680px) {
  .sidebar { position: fixed; left: 0; top: 0; bottom: 0; z-index: 100; transform: translateX(0); transition: transform var(--transition); }
  .sidebar.hidden { transform: translateX(-100%); }
  .back-btn { display: flex; }
  .chat-area { width: 100%; }
}

/* ── PWA / Safe area (notch + bottom bar on Android/iOS) ── */
@media (display-mode: standalone) {
  body:not(.login-page):not(.admin-page) {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .sidebar { top: env(safe-area-inset-top); }
  .msg-input-row {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}
