* { box-sizing: border-box; }
body { margin: 0; font-family: "Segoe UI", "PingFang TC", sans-serif; background: #8cabd9; height: 100vh; overflow: hidden; }
.app { display: flex; height: 100vh; max-width: 1200px; margin: 0 auto; background: #fff; box-shadow: 0 0 24px rgba(0,0,0,.12); }
.sidebar { width: 300px; border-right: 1px solid #e5e7eb; display: flex; flex-direction: column; background: #f8fafc; }
.sidebar-head { padding: 12px; border-bottom: 1px solid #e5e7eb; }
.sidebar-head h1 { margin: 8px 0; font-size: 1.1rem; }
.sidebar-head input, .sidebar-head select { width: 100%; margin: 6px 0; padding: 6px; }
.sidebar-head button { width: 100%; margin-top: 4px; padding: 8px; cursor: pointer; }
.account-proxy-line {
  margin: 4px 0 0;
  font-size: 0.72rem;
  line-height: 1.35;
  color: #475569;
  word-break: break-all;
}
.account-proxy-line.is-socks { color: #047857; font-weight: 600; }
.account-proxy-line.is-direct { color: #b45309; }
.btn-check-proxy { font-size: 0.85rem; background: #f1f5f9; border: 1px solid #cbd5e1; }
.back { font-size: 0.85rem; color: #2563eb; text-decoration: none; }
.back-console-btn {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  background: #fff;
  border: 1px solid #cbd5e1;
  color: #334155;
  font-weight: 600;
  box-shadow: 0 1px 3px rgba(15, 23, 42, 0.06);
  transition: background 0.15s, border-color 0.15s, color 0.15s;
}
.back-console-btn:hover {
  background: #f8fafc;
  border-color: #06c755;
  color: #047857;
  text-decoration: none;
}
.chat-nav { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1; }
.chat-nav li { padding: 12px 14px; border-bottom: 1px solid #eee; cursor: pointer; }
.chat-nav li:hover { background: #eef2ff; }
.chat-nav li.active { background: #dbeafe; font-weight: 600; }
.chat-nav li.nav-admin { border-left: 4px solid #d97706; background: linear-gradient(90deg, #fffbeb 0%, transparent 55%); }
.chat-nav li.nav-admin-co { border-left-color: #2563eb; background: linear-gradient(90deg, #eff6ff 0%, transparent 55%); }
.chat-nav li.active.nav-admin { background: linear-gradient(90deg, #fef3c7 0%, #dbeafe 100%); }
.chat-nav li.active.nav-admin-co { background: linear-gradient(90deg, #dbeafe 0%, #dbeafe 100%); }
.chat-nav li.nav-loading,
.chat-nav li.nav-load-err {
  cursor: default;
  color: #64748b;
  font-size: 0.85rem;
}
.chat-nav li.nav-load-err { color: #b91c1c; }
.chat-nav li.nav-loading:hover,
.chat-nav li.nav-load-err:hover { background: transparent; }
.chat-nav .mid { font-size: 0.7rem; color: #888; word-break: break-all; }
.chat-loading-hint { padding: 16px; color: #64748b; font-size: 0.9rem; margin: 0; }
.role-badge {
  display: inline-block;
  margin-left: 4px;
  padding: 0 6px;
  border-radius: 4px;
  font-size: 0.65rem;
  font-weight: 700;
  vertical-align: middle;
}
.role-badge.admin { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.role-badge.co_admin { background: #dbeafe; color: #1e40af; border: 1px solid #93c5fd; }
.join-pending-hint { font-size: 0.72rem; color: #b45309; font-weight: 600; margin-top: 2px; }
.btn-header.btn-admin { border-color: #fcd34d; background: #fffbeb; color: #92400e; }
.btn-header.btn-admin:not(:disabled):hover { background: #fef3c7; border-color: #d97706; }
.admin-modal-panel { width: min(100%, 480px); max-height: 85vh; overflow: auto; }
.admin-join-list table { width: 100%; font-size: 0.82rem; border-collapse: collapse; }
.admin-join-list th, .admin-join-list td { border-bottom: 1px solid #eee; padding: 8px 6px; text-align: left; vertical-align: top; }
.admin-join-list .btn-sm { padding: 4px 10px; margin: 2px 4px 2px 0; font-size: 0.78rem; cursor: pointer; }
.jr-toolbar, .jr-pager { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; align-items: center; }
.jr-search-wrap { display: inline-flex; align-items: center; gap: 6px; font-size: 0.82rem; margin: 0; color: #334155; }
.jr-search { min-width: 180px; max-width: 100%; flex: 1 1 180px; padding: 6px 8px; margin: 0; border: 1px solid #cbd5e1; border-radius: 6px; }
.jr-search:focus { outline: 2px solid #06c755; border-color: #06c755; }
.jr-pager { margin-top: 4px; }
.btn-primary-sm { background: #06c755; color: #fff; border: none; border-radius: 6px; }
.btn-primary-sm:hover { background: #05a847; }
.jr-th-check { width: 2.2rem; text-align: center; }
.jr-wrap table { width: 100%; }
.chat-title-badge { font-size: 0.75rem; font-weight: 700; margin-left: 6px; vertical-align: middle; }
.chat-nav-title { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.member-count { font-size: 0.75rem; color: #2563eb; font-weight: normal; white-space: nowrap; }
.unread-badge { display: inline-block; min-width: 1.1em; padding: 1px 6px; margin-left: 4px; border-radius: 999px; background: #ef4444; color: #fff; font-size: 0.7rem; font-weight: 700; line-height: 1.3; }
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; background: #7494c2; }
.chat-header { background: #fff; padding: 12px 16px; display: flex; justify-content: space-between; align-items: center; border-bottom: 1px solid #e5e7eb; gap: 12px; }
.chat-header h2 { margin: 0; font-size: 1rem; flex: 1; min-width: 0; }
.chat-header-actions { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.btn-header {
  border: 1px solid #d1d5db;
  background: #fff;
  color: #334155;
  font-size: 0.78rem;
  padding: 6px 10px;
  border-radius: 8px;
  cursor: pointer;
}
.btn-header:hover:not(:disabled) { background: #f8fafc; border-color: #06c755; color: #047857; }
.btn-header:disabled { opacity: 0.45; cursor: not-allowed; }
.profile-modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; }
.profile-modal.hidden { display: none !important; }
.profile-modal-backdrop { position: absolute; inset: 0; background: rgba(15,23,42,.45); }
.profile-modal-panel {
  position: relative;
  width: min(100%, 380px);
  background: #fff;
  border-radius: 12px;
  padding: 18px 18px 14px;
  box-shadow: 0 16px 40px rgba(0,0,0,.18);
}
.profile-modal-panel h3 { margin: 0 0 6px; font-size: 1.05rem; }
.profile-hint { margin: 0 0 14px; font-size: 0.75rem; color: #64748b; line-height: 1.4; }
.profile-avatar-row { display: flex; align-items: center; gap: 14px; margin-bottom: 14px; }
.profile-avatar-preview {
  width: 72px; height: 72px; border-radius: 50%;
  background: #e2e8f0; color: #475569; font-weight: 700; font-size: 1.5rem;
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}
.profile-avatar-preview img { width: 100%; height: 100%; object-fit: cover; }
.profile-file-label {
  font-size: 0.85rem; color: #2563eb; cursor: pointer; font-weight: 600;
}
.profile-file-label:hover { text-decoration: underline; }
.profile-field { display: block; font-size: 0.82rem; color: #475569; margin-bottom: 14px; }
.profile-field input {
  display: block; width: 100%; margin-top: 6px; padding: 9px 10px;
  border: 1px solid #d1d5db; border-radius: 8px; font-size: 0.95rem;
}
.profile-modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.btn-secondary, .btn-primary {
  padding: 8px 14px; border-radius: 8px; font-size: 0.88rem; cursor: pointer; border: none;
}
.btn-secondary { background: #e5e7eb; color: #334155; }
.btn-primary { background: #06c755; color: #fff; font-weight: 600; }
.profile-error { margin: 10px 0 0; font-size: 0.8rem; color: #dc2626; }
.profile-error.hidden { display: none; }
.ws-on { color: #059669; font-size: 0.8rem; }
.ws-off { color: #6b7280; font-size: 0.8rem; }
.messages { flex: 1; overflow: auto; padding: 12px 14px 16px; display: flex; flex-direction: column; gap: 6px; }
.bubble-row { display: flex; flex-direction: row; align-items: flex-end; gap: 6px; max-width: 92%; }
.bubble-row.out { align-self: flex-end; flex-direction: row-reverse; }
.bubble-row.in { align-self: flex-start; }
.bubble-col { display: flex; flex-direction: column; min-width: 0; max-width: min(100%, 320px); }
.bubble-row.out .bubble-col { align-items: flex-end; }
.bubble-row.in .bubble-col { align-items: flex-start; }
.bubble-body-row { display: flex; flex-direction: row; align-items: flex-end; gap: 6px; max-width: 100%; }
.bubble-row.out .bubble-body-row { flex-direction: row-reverse; }
.msg-avatar-wrap { position: relative; width: 36px; height: 36px; flex-shrink: 0; }
.msg-avatar-wrap .msg-avatar {
  position: absolute; inset: 0; width: 100%; height: 100%;
  border-radius: 50%; object-fit: cover;
  border: 2px solid rgba(255,255,255,.85);
  opacity: 0; z-index: 2; transition: opacity 0.15s ease;
}
.msg-avatar-wrap.is-loaded .msg-avatar { opacity: 1; }
.msg-avatar-fallback {
  position: absolute; inset: 0; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.9rem; font-weight: 700; color: #334155;
  background: #e2e8f0; border: 2px solid rgba(255,255,255,.85);
  z-index: 1;
}
.msg-avatar-wrap.is-loaded .msg-avatar-fallback {
  opacity: 0; visibility: hidden; pointer-events: none;
}
.bubble-name { font-size: 0.72rem; color: #334155; margin: 0 0 3px 2px; font-weight: 600; }
.bubble-row.out .bubble-name { display: none; }
.bubble {
  position: relative;
  padding: 9px 12px;
  border-radius: 16px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  font-size: 0.95rem;
  max-width: 100%;
  box-shadow: 0 1px 1px rgba(0,0,0,.06);
}
.bubble.in {
  background: #fff;
  color: #111;
  border-top-left-radius: 4px;
}
.bubble.in::before {
  content: "";
  position: absolute;
  left: -5px;
  bottom: 8px;
  border: 6px solid transparent;
  border-right-color: #fff;
  filter: drop-shadow(-1px 1px 0 rgba(0,0,0,.04));
}
.bubble.out {
  background: #95ec69;
  color: #111;
  border-top-right-radius: 4px;
}
.bubble.out::before {
  content: "";
  position: absolute;
  right: -5px;
  bottom: 8px;
  border: 6px solid transparent;
  border-left-color: #95ec69;
}
.bubble.bubble-media {
  padding: 0;
  background: transparent;
  box-shadow: none;
  border-radius: 0;
}
.bubble.bubble-media::before { display: none; }
.bubble-side-meta {
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 2px;
  font-size: 0.68rem;
  line-height: 1.2;
  color: rgba(255,255,255,.88);
  padding-bottom: 2px;
  min-width: 2.5em;
}
.bubble-row.in .bubble-side-meta { color: rgba(255,255,255,.85); align-items: flex-start; }
.bubble-side-meta .btn-unsend {
  margin-top: 4px;
}
.btn-unsend {
  font-size: 0.62rem;
  padding: 1px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.45);
  background: rgba(0,0,0,.12);
  color: inherit;
  cursor: pointer;
  margin-top: 2px;
}
.btn-unsend:hover { background: rgba(0,0,0,.22); }
.btn-unsend.hidden { display: none; }
.btn-admin-msg {
  display: block;
  margin-top: 2px;
  padding: 2px 6px;
  font-size: 0.65rem;
  border-radius: 4px;
  border: 1px solid rgba(180, 83, 9, 0.45);
  background: rgba(255, 251, 235, 0.95);
  color: #92400e;
  cursor: pointer;
}
.btn-admin-msg:hover { background: #fef3c7; }
.btn-admin-msg.hidden { display: none; }
.btn-admin-kick {
  display: block;
  margin-top: 2px;
  padding: 2px 6px;
  font-size: 0.65rem;
  border-radius: 4px;
  border: 1px solid rgba(220, 38, 38, 0.4);
  background: rgba(254, 242, 242, 0.95);
  color: #b91c1c;
  cursor: pointer;
}
.btn-admin-kick:hover { background: #fee2e2; }
.btn-admin-kick.hidden { display: none; }
.bubble-name.bubble-name-admin {
  cursor: pointer;
  color: #92400e;
  text-decoration: underline dotted;
  text-underline-offset: 2px;
}
.bubble-name.bubble-name-admin:hover { color: #b45309; }
.members-kick-btn { margin-left: 8px; }
.read-count { color: #6ee7b7; font-weight: 600; white-space: nowrap; }
.bubble-row.in .read-count { display: none; }
.time { white-space: nowrap; opacity: 0.95; }
.chat-img {
  display: block;
  max-width: min(240px, 72vw);
  max-height: 280px;
  border-radius: 12px;
  object-fit: contain;
  background: rgba(0,0,0,.08);
}
.img-placeholder { font-size: 0.85rem; color: #fff; padding: 8px; }
.composer { background: #fff; padding: 8px 10px 10px; border-top: 1px solid #e5e7eb; }
.composer-main { display: flex; gap: 6px; align-items: flex-end; }
.composer-icon-btn {
  width: 40px;
  height: 40px;
  padding: 0;
  border: none;
  border-radius: 10px;
  background: transparent;
  color: #64748b;
  cursor: pointer;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s ease, color 0.15s ease;
}
.composer-icon-btn:hover:not(:disabled) {
  background: #f1f5f9;
  color: #06c755;
}
.composer-icon-btn:active:not(:disabled) { background: #e2e8f0; }
.composer-icon-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.composer-icon-btn.is-active {
  color: #06c755;
  background: #ecfdf5;
}
.composer-icon {
  display: block;
  pointer-events: none;
}
.sticker-picker { border: 1px solid #e5e7eb; border-radius: 10px; margin-bottom: 8px; background: #f9fafb; max-height: 220px; display: flex; flex-direction: column; }
.sticker-picker.hidden { display: none !important; }
.sticker-picker-head { display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid #eee; }
.sticker-tab { border: none; background: #e5e7eb; padding: 6px 10px; border-radius: 6px; cursor: pointer; font-size: 0.85rem; }
.sticker-tab.active { background: #06c755; color: #fff; }
#stickerPackSelect { flex: 1; padding: 6px; font-size: 0.85rem; }
.sticker-close { border: none; background: transparent; font-size: 1.4rem; line-height: 1; cursor: pointer; color: #666; padding: 0 4px; }
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; padding: 8px; overflow: auto; flex: 1; }
.sticker-grid button { border: none; background: #fff; border-radius: 8px; padding: 4px; cursor: pointer; aspect-ratio: 1; display: flex; align-items: center; justify-content: center; }
.sticker-grid button:hover { background: #ecfdf5; box-shadow: 0 0 0 2px #06c755; }
.sticker-grid img { max-width: 64px; max-height: 64px; object-fit: contain; }
.sticker-hint { margin: 0; padding: 4px 8px 8px; font-size: 0.72rem; color: #666; }
.composer textarea { flex: 1; resize: none; padding: 10px; border: 1px solid #d1d5db; border-radius: 8px; font-family: inherit; }
.composer-main .btn-send {
  min-height: 40px;
  padding: 0 20px;
  border: none;
  background: #06c755;
  color: #fff;
  border-radius: 8px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.composer-main .btn-send:disabled { background: #9ca3af; cursor: not-allowed; }
.composer-icon-btn:disabled { background: transparent !important; color: #94a3b8 !important; opacity: 1; }
.sticker-box { margin-top: 8px; font-size: 0.85rem; }
.sticker-box label { display: block; margin: 4px 0; }
.sticker-box input { width: 100%; padding: 6px; margin-top: 2px; }
.sticker-box .hint { color: #666; margin: 4px 0; }
.sticker-img { max-width: 120px; max-height: 120px; display: block; }
.system { text-align: center; color: #eef3fb; font-size: 0.8rem; padding: 8px; }
.chat-toast { position: absolute; left: 12px; right: 12px; bottom: 120px; z-index: 20; background: rgba(30,30,30,.92); color: #fff; padding: 10px 12px; border-radius: 8px; font-size: 0.82rem; line-height: 1.4; white-space: pre-wrap; opacity: 0; pointer-events: none; transition: opacity .2s; max-height: 40vh; overflow: auto; }
.chat-toast.show { opacity: 1; pointer-events: auto; }
.main { position: relative; }
