* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: #0f172a;
  color: #e2e8f0;
  -webkit-text-size-adjust: 100%;
}
.hidden { display: none !important; }
.panel { min-height: 100vh; }
.auth-panel { max-width: 420px; margin: 0 auto; padding: 48px 24px; }
.brand h1 { margin: 0 0 8px; font-size: 32px; }
.brand p { color: #94a3b8; margin-top: 0; }
.tabs { display: flex; gap: 8px; margin: 24px 0 12px; }
.tabs button { flex: 1; background: #1e293b; color: #cbd5e1; border: 1px solid #334155; padding: 10px; border-radius: 10px; cursor: pointer; }
.tabs button.active { background: #2563eb; color: white; border-color: #2563eb; }
#auth-form { display: grid; gap: 12px; }
#auth-form input, .search-box input, .group-box input, .wx-input-wrap input {
  width: 100%; padding: 12px 14px; border-radius: 10px; border: 1px solid #334155; background: #1e293b; color: #f8fafc;
  font-size: 16px;
}
#auth-form button, #create-group-btn, #logout-btn, #rename-group-btn, #announcement-save, .msg-actions button {
  border: none; border-radius: 10px; padding: 8px 12px; cursor: pointer; background: #2563eb; color: white;
}
.error { color: #f87171; min-height: 20px; }
#main-view {
  display: grid;
  grid-template-columns: 320px 1fr;
  height: 100vh;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
}
.sidebar { background: #111827; border-right: 1px solid #1f2937; display: flex; flex-direction: column; min-height: 0; overflow: hidden; height: 100%; }
.sidebar-header, .search-box, .group-box { padding: 16px; border-bottom: 1px solid #1f2937; }
.sidebar-header { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.sidebar-header small { color: #94a3b8; display: block; }
.sidebar-header button { font-size: 12px; padding: 6px 10px; }
#notify-toggle { background: #334155; }
.group-box { display: grid; grid-template-columns: 1fr auto; gap: 8px; }
#conversation-list { overflow-y: auto; flex: 1; }
.conv-item { padding: 14px 16px; border-bottom: 1px solid #1f2937; cursor: pointer; display: flex; align-items: center; gap: 10px; }
.conv-item:hover, .conv-item.active { background: #1f2937; }
.conv-item.has-unread .conv-body strong { font-weight: 700; }
.conv-body { flex: 1; min-width: 0; }
.conv-item small { color: #94a3b8; display: block; margin-top: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-badge {
  flex-shrink: 0;
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 20px;
  text-align: center;
}
.sidebar-user { position: relative; flex: 1; min-width: 0; }
.total-unread-badge {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef4444;
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
}
.online-dot { color: #4ade80; margin-right: 4px; }
.chat-area { display: flex; flex-direction: column; background: #0b1220; min-height: 0; height: 100%; overflow: hidden; }
.chat-header { padding: 16px 20px; border-bottom: 1px solid #1f2937; display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; flex-shrink: 0; }
.chat-header-main { flex: 1; min-width: 0; }
.chat-header-main h2 { margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-back {
  display: none;
  align-items: center;
  justify-content: center;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 10px;
  background: #1e293b;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  flex-shrink: 0;
}
.chat-header small { color: #94a3b8; }
#group-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.announcement-panel {
  padding: 12px 20px;
  background: #172554;
  border-bottom: 1px solid #1e3a8a;
  flex-shrink: 0;
}
.announcement-head { font-weight: 700; color: #bfdbfe; margin-bottom: 8px; }
.announcement-view { color: #dbeafe; font-size: 14px; line-height: 1.5; white-space: pre-wrap; }
.announcement-edit { display: grid; gap: 8px; margin-top: 8px; }
.announcement-edit textarea {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #3b82f6;
  background: #0f172a; color: #fff; resize: vertical;
}
.announcement-edit button { width: fit-content; }
.invite-panel {
  padding: 12px 20px;
  background: #0f172a;
  border-bottom: 1px solid #1f2937;
  flex-shrink: 0;
}
.invite-head { font-weight: 700; color: #cbd5e1; margin-bottom: 8px; }
.invite-panel input {
  width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid #334155;
  background: #1e293b; color: #fff;
}
.call-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.call-actions button { background: #059669; border: none; color: #fff; border-radius: 8px; padding: 8px 12px; cursor: pointer; }
.call-modal {
  position: fixed; inset: 0; background: rgba(0,0,0,0.75); display: grid; place-items: center; z-index: 1000;
}
.call-card {
  width: min(520px, 92vw); background: #111827; border: 1px solid #334155; border-radius: 16px; padding: 20px;
  display: grid; gap: 12px; text-align: center;
}
.call-card video { width: 100%; max-height: 220px; background: #000; border-radius: 10px; }
.call-card video.hidden { display: none; }
#call-remote-audio, .call-remote-sink { position: absolute; width: 1px; height: 1px; opacity: 0.01; pointer-events: none; overflow: hidden; }
#call-unmute { background: #f59e0b; color: #111; border: none; border-radius: 999px; padding: 10px 16px; cursor: pointer; font-size: 15px; }
.call-btns { display: flex; justify-content: center; gap: 10px; flex-wrap: wrap; }
.call-btns button { border: none; border-radius: 999px; padding: 10px 18px; cursor: pointer; color: #fff; }
#call-accept { background: #059669; }
#call-decline, #call-hangup { background: #dc2626; }
.member-bar { padding: 10px 20px; border-bottom: 1px solid #1f2937; display: flex; flex-wrap: wrap; gap: 8px; flex-shrink: 0; }
.member-chip { background: #1e293b; border: 1px solid #334155; border-radius: 999px; padding: 4px 10px; font-size: 12px; }
.member-chip.owner { border-color: #f59e0b; color: #fbbf24; }
.member-chip.admin { border-color: #38bdf8; color: #7dd3fc; }
#chat-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; height: 100%; overflow: hidden; }
#chat-panel.hidden { display: none !important; }
.messages { flex: 1; min-height: 0; overflow-y: auto; padding: 20px; display: flex; flex-direction: column; gap: 10px; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.msg { max-width: 70%; width: fit-content; padding: 10px 14px; border-radius: 14px; background: #1e293b; word-break: break-word; align-self: flex-start; }
.msg.me { align-self: flex-end; background: #2563eb; }
.msg.msg-media {
  padding: 4px;
  max-width: min(220px, 72vw);
  background: #1e293b;
}
.msg.me.msg-media { background: #2563eb; }
.msg.msg-media .meta { display: none; }
.msg.msg-media .body { line-height: 0; }
.msg.msg-media .body img {
  width: auto;
  max-width: 100%;
  height: auto;
  border-radius: 10px;
  display: block;
}
.msg.msg-media .body.sticker-msg img { max-width: 120px; }
.msg.msg-media .body audio { width: 200px; }
.msg.msg-media .msg-actions { margin-top: 4px; text-align: right; }
.msg.msg-media.me .read-tag {
  display: block;
  text-align: right;
  font-size: 11px;
  opacity: 0.75;
  margin-top: 4px;
  line-height: 1.2;
}
.msg.call-log { max-width: 82%; font-size: 13px; border: 1px dashed #475569; background: #1e293b; }
.msg.me.call-log { background: #1d4ed8; border-color: #60a5fa; }
.msg.call-log .call-log-text { color: #e2e8f0; }
.msg .meta { font-size: 12px; opacity: 0.75; margin-bottom: 4px; display: flex; justify-content: space-between; gap: 8px; }
.msg .body img { max-width: min(240px, 100%); border-radius: 10px; display: block; }
.msg .body audio { width: min(220px, 100%); max-width: 100%; }
.msg.recalled { opacity: 0.7; font-style: italic; }
.msg-actions { margin-top: 6px; }
.msg-actions button { font-size: 12px; padding: 4px 8px; background: rgba(255,255,255,0.15); }
.read-tag { font-size: 11px; opacity: 0.8; }
.composer {
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  background: #1a1a1a;
  border-top: 1px solid #2a2a2a;
}
.wx-panel {
  padding: 16px 12px 8px;
  background: #1a1a1a;
  border-bottom: 1px solid #2a2a2a;
}
.wx-panel.hidden { display: none; }
.wx-panel-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px 8px;
}
.wx-panel-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  border: none;
  background: transparent;
  color: #d1d5db;
  font-size: 12px;
  cursor: pointer;
  padding: 4px;
}
.wx-panel-icon {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  background: #2a2a2a;
  display: grid;
  place-items: center;
  font-size: 26px;
}
.wx-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px calc(8px + env(safe-area-inset-bottom, 0px));
  background: #1a1a1a;
}
.wx-side-btn {
  width: 36px;
  height: 36px;
  border: none;
  background: transparent;
  color: #e5e7eb;
  font-size: 26px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  display: grid;
  place-items: center;
  padding: 0;
}
.wx-plus-btn {
  font-size: 28px;
  font-weight: 300;
}
.wx-input-wrap {
  flex: 1;
  min-width: 0;
  background: #2a2a2a;
  border: 1px solid #3a3a3a;
  border-radius: 6px;
  min-height: 38px;
  display: flex;
  align-items: center;
  padding: 0 10px;
}
.wx-input-wrap input {
  width: 100%;
  border: none;
  background: transparent;
  color: #f9fafb;
  font-size: 16px;
  outline: none;
  padding: 8px 0;
}
.wx-hold-talk {
  flex: 1;
  min-width: 0;
  height: 38px;
  border: none;
  border-radius: 6px;
  background: #2a2a2a;
  color: #e5e7eb;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}
.wx-hold-talk.hidden { display: none; }
.wx-hold-talk.recording { background: #374151; color: #fff; }
.wx-input-wrap.hidden { display: none; }
.wx-send-btn {
  height: 32px;
  min-width: 52px;
  padding: 0 12px;
  border: none;
  border-radius: 4px;
  background: #07c160;
  color: #fff;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  flex-shrink: 0;
}
.wx-send-btn.hidden { display: none; }
.wx-plus-btn.hidden { display: none; }
.wx-call-item.hidden { display: none; }
.wx-plus-btn.active { color: #07c160; }
.emoji-panel {
  padding: 10px 12px 6px;
  background: #1a1a1a;
  border-bottom: 1px solid #2a2a2a;
  max-height: 220px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.emoji-panel.hidden { display: none; }
.emoji-tabs {
  display: flex;
  gap: 4px;
  padding: 0 8px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.emoji-tabs::-webkit-scrollbar { display: none; }
.emoji-tab {
  flex-shrink: 0;
  border: none;
  background: #2a2a2a;
  color: #d1d5db;
  font-size: 12px;
  padding: 6px 12px;
  border-radius: 14px;
  cursor: pointer;
  max-width: 88px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.emoji-tab.active { background: #07c160; color: #fff; }
.emoji-tab-add { font-size: 16px; padding: 4px 12px; }
.emoji-content { min-height: 120px; }
.emoji-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 4px;
}
.emoji-item {
  width: 100%;
  aspect-ratio: 1;
  border: none;
  background: transparent;
  font-size: 24px;
  line-height: 1;
  cursor: pointer;
  border-radius: 8px;
  padding: 0;
  display: grid;
  place-items: center;
}
.emoji-item:hover { background: #2a2a2a; }
.emoji-item:active { background: #374151; }
.emoji-item:active { background: #374151; }
.sticker-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  padding: 0 4px 8px;
}
.sticker-grid.hidden { display: none; }
.sticker-item {
  position: relative;
  border: none;
  background: #2a2a2a;
  border-radius: 10px;
  padding: 6px;
  cursor: pointer;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
}
.sticker-item img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  pointer-events: none;
}
.sticker-del {
  position: absolute;
  top: 2px;
  right: 4px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: rgba(0,0,0,0.55);
  color: #fff;
  font-size: 14px;
  line-height: 18px;
  text-align: center;
  display: none;
}
.sticker-item:hover .sticker-del { display: block; }
.sticker-add {
  flex-direction: column;
  color: #94a3b8;
  font-size: 28px;
  gap: 2px;
}
.sticker-add small { font-size: 11px; }
.sticker-pack-del {
  grid-column: 1 / -1;
  margin-top: 4px;
  border: 1px solid #374151;
  background: transparent;
  color: #f87171;
  border-radius: 8px;
  padding: 8px;
  cursor: pointer;
  font-size: 13px;
}
.sticker-empty {
  grid-column: 1 / -1;
  text-align: center;
  color: #94a3b8;
  padding: 24px;
  font-size: 14px;
}
.msg .body.sticker-msg img { max-width: 120px; background: transparent; border-radius: 0; }
.wx-emoji-btn { font-size: 24px; }
.wx-emoji-btn.active { color: #07c160; }
.wx-emoji-btn.hidden { display: none; }
#mode-switch { order: 0; }
.wx-input-wrap, .wx-hold-talk { order: 1; }
.wx-plus-btn { order: 2; }
.wx-emoji-btn { order: 3; }
.wx-send-btn { order: 4; }
#call-accept, #call-decline, #call-hangup { min-height: 44px; min-width: 44px; }
.empty { margin: auto; color: #64748b; font-size: 18px; flex: 1; display: grid; place-items: center; }
.loading-hint { padding: 24px; text-align: center; color: #94a3b8; font-size: 14px; }
.loading-hint.error { color: #f87171; }
.dropdown { margin-top: 8px; background: #1e293b; border: 1px solid #334155; border-radius: 10px; overflow: hidden; }
.dropdown div { padding: 10px 12px; cursor: pointer; }
.dropdown div:hover { background: #334155; }

/* 手机 / 平板竖屏：单栏，会话列表 ↔ 聊天页切换 */
@media (max-width: 768px) {
  body { overflow: hidden; }
  .auth-panel { padding: 32px 16px; max-width: 100%; }
  .brand h1 { font-size: 26px; }
  #main-view {
    grid-template-columns: 1fr;
    height: 100dvh;
    max-height: 100dvh;
    overflow: hidden;
  }
  .sidebar {
    height: 100dvh;
    border-right: none;
    padding-bottom: env(safe-area-inset-bottom, 0px);
  }
  .chat-area {
    height: 100dvh;
    overflow: hidden;
  }
  #main-view:not(.mobile-chat-open) .chat-area { display: none; }
  #main-view.mobile-chat-open .sidebar { display: none; }
  #chat-empty { display: none !important; }
  .chat-back { display: inline-flex !important; }
  .sidebar-header {
    flex-wrap: wrap;
    padding-top: calc(16px + env(safe-area-inset-top, 0px));
  }
  .sidebar-header > div { flex: 1 1 100%; }
  .sidebar-header button { flex: 1; min-height: 40px; }
  .group-box { grid-template-columns: 1fr; }
  .group-box button { width: 100%; min-height: 44px; }
  .conv-item { padding: 16px; }
  .chat-header {
    padding: 12px 14px;
    padding-top: calc(12px + env(safe-area-inset-top, 0px));
  }
  .chat-header-main h2 { font-size: 17px; }
  .call-actions { display: none !important; }
  .messages { padding: 12px; }
  .msg { max-width: 85%; width: fit-content; }
  .msg.msg-media { max-width: min(200px, 78vw); }
  .wx-bar { padding: 6px 8px calc(6px + env(safe-area-inset-bottom, 0px)); }
  .call-card {
    width: 100%;
    max-width: 100%;
    min-height: 100dvh;
    border-radius: 0;
    padding: 20px 16px calc(20px + env(safe-area-inset-bottom, 0px));
    padding-top: calc(20px + env(safe-area-inset-top, 0px));
  }
  .call-card video { max-height: 40vh; }
  .call-btns button { min-height: 48px; min-width: 100px; font-size: 16px; }
}

@media (min-width: 769px) {
  .chat-back { display: none !important; }
  .composer { background: #0b1220; border-top-color: #1f2937; }
  .wx-panel { display: none !important; }
  .emoji-panel { background: #0b1220; border-bottom-color: #1f2937; max-height: 200px; }
  .emoji-grid { grid-template-columns: repeat(10, 1fr); }
  .sticker-grid { grid-template-columns: repeat(6, 1fr); }
  .wx-bar { padding: 12px 16px; background: #0b1220; }
  .wx-side-btn { display: none; }
  .wx-emoji-btn { display: grid !important; order: 0; width: 40px; height: 40px; font-size: 26px; }
  .wx-input-wrap { display: flex !important; border-radius: 10px; min-height: 44px; order: 1; }
  .wx-hold-talk { display: none !important; }
  .wx-plus-btn { display: none !important; }
  .wx-send-btn { display: inline-block !important; height: 40px; min-width: 72px; border-radius: 10px; order: 2; }
  .wx-send-btn.hidden { display: inline-block !important; }
}
