/* ── WeChat-style light theme (unified, iOS-friendly) ── */
:root {
  --brand: #07c160;
  --brand-dark: #06ad56;
  --brand-light: #e8f8ef;
  --accent: #07c160;
  --mine: #95ec69;
  --mine-text: #000;
  --page: #ededed;
  --surface: #ffffff;
  --header: #ededed;
  --panel: #ededed;
  --chat-bg: #ededed;
  --line: #d9d9d9;
  --line-soft: #e6e6e6;
  --text: #191919;
  --text-secondary: #888888;
  --sidebar: #ffffff;
  --sidebar-hover: #f5f5f5;
  --sidebar-active: #07c160;
  --sidebar-active-bg: #ededed;
  --danger: #fa5151;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .04);
  --shadow-md: 0 2px 12px rgba(0, 0, 0, .08);
  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 16px;
  --radius-full: 999px;
  --sidebar-w: clamp(300px, 32vw, 380px);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue",
    Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --transition: .15s ease;
  color-scheme: light;
}

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  background: var(--page);
}

html.app-lock {
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  color: var(--text);
  background: var(--page);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

body.app-lock {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-overflow-scrolling: auto;
}

.app-root {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  height: calc(var(--vh, 1vh) * 100);
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--page);
  display: flex;
  flex-direction: column;
}

button,
input,
textarea {
  font: inherit;
  color: inherit;
}

button {
  border: 0;
  cursor: pointer;
  background: none;
  padding: 0;
}

input,
textarea {
  background: transparent;
}

.hidden {
  display: none !important;
}

/* ── Auth / Install ── */
.auth-shell,
.install-page {
  flex: 1;
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: grid;
  place-items: center;
  padding: 24px;
  padding: max(24px, env(safe-area-inset-top)) 24px max(24px, env(safe-area-inset-bottom));
  background: var(--page);
}

.auth-panel,
.install-box {
  width: min(400px, 100%);
  background: var(--surface);
  border-radius: var(--radius-md);
  padding: 36px 32px 32px;
  box-shadow: var(--shadow-md);
}

.auth-logo {
  width: 64px;
  height: 64px;
  margin: 0 auto 16px;
  display: grid;
  place-items: center;
}

.auth-panel h1,
.install-box h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 600;
  text-align: center;
}

.auth-panel p,
.install-box p {
  margin: 0 0 28px;
  color: var(--text-secondary);
  text-align: center;
  font-size: 14px;
}

.auth-form,
.install-box form {
  display: grid;
  gap: 16px;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 500;
}

.auth-form input,
.install-box input,
.contacts-search input,
.admin-toolbar input,
.admin-toolbar select,
.admin-input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  outline: none;
  background: #fff;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.auth-form input:focus,
.install-box input:focus,
.contacts-search input:focus,
.admin-toolbar input:focus,
.admin-input:focus,
.composer textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(7, 193, 96, .12);
}

.btn-primary,
.auth-form button[type="submit"],
.install-box button[type="submit"],
.link-button {
  height: 46px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font-weight: 500;
  text-align: center;
  text-decoration: none;
  transition: background var(--transition);
}

.btn-primary:hover,
.auth-form button[type="submit"]:hover,
.install-box button[type="submit"]:hover,
.link-button:hover {
  background: var(--brand-dark);
}

.link-button {
  display: grid;
  place-items: center;
}

.form-error,
.notice {
  min-height: 20px;
  margin-top: 12px;
  color: var(--danger);
  font-size: 13px;
  text-align: center;
}

.notice {
  min-height: 0;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  margin-bottom: 14px;
  text-align: left;
}

.notice.success {
  color: #0f7a3d;
  background: #e8f8ef;
}

.notice.error {
  background: #fff1f1;
}

.install-box label {
  display: grid;
  gap: 6px;
  color: var(--text-secondary);
  font-size: 13px;
}

.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 16px;
}

.tab {
  height: 40px;
  border-radius: var(--radius-sm);
  background: var(--line-soft);
  color: var(--text-secondary);
  font-weight: 500;
}

.tab.active {
  background: var(--brand);
  color: #fff;
}

/* ── Chat shell ── */
.chat-shell {
  flex: 1;
  min-height: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--page);
}

/* ── Sidebar ── */
.sidebar {
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--sidebar);
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  border-right: 1px solid var(--line);
}

.sidebar-head {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  padding-top: max(8px, env(safe-area-inset-top));
  background: var(--header);
  border-bottom: 1px solid var(--line);
  min-height: 56px;
  flex: none;
}

.sidebar-search-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 12px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-secondary);
  pointer-events: none;
}

.sidebar-search {
  width: 100%;
  height: 36px;
  border: 0;
  border-radius: var(--radius-sm);
  padding: 0 14px 0 38px;
  background: var(--surface);
  outline: none;
  font-size: 14px;
  transition: background var(--transition);
}

.sidebar-search:focus {
  background: var(--surface);
  box-shadow: inset 0 0 0 1px var(--line);
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  flex: none;
  text-decoration: none;
  transition: background var(--transition), color var(--transition);
}

.icon-btn:hover {
  background: var(--sidebar-hover);
  color: var(--text);
}

.icon-btn-sm {
  width: 32px;
  height: 32px;
}

.tab-bar {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--header);
  flex: none;
}

.tab-bar .tab {
  flex: 1;
  height: 44px;
  border-radius: 0;
  background: transparent;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  position: relative;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition);
}

.tab-bar .tab:hover {
  color: var(--text);
}

.tab-bar .tab.active {
  background: transparent;
  color: var(--brand);
  border-bottom-color: var(--brand);
}

.panel-list {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
}

.panel-list::-webkit-scrollbar,
.messages::-webkit-scrollbar,
.table-wrap::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.panel-list::-webkit-scrollbar-thumb,
.messages::-webkit-scrollbar-thumb,
.table-wrap::-webkit-scrollbar-thumb {
  background: rgba(0, 0, 0, .15);
  border-radius: 6px;
}

.list-item {
  width: 100%;
  min-height: 72px;
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) auto;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  color: var(--text);
  background: transparent;
  text-align: left;
  transition: background var(--transition);
}

.list-item:hover {
  background: var(--sidebar-hover);
}

.list-item.active {
  background: var(--sidebar-active-bg);
}

.contact-item {
  grid-template-columns: 54px minmax(0, 1fr);
}

.avatar {
  width: 54px;
  height: 54px;
  border-radius: var(--radius-full);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 600;
  font-size: 20px;
  flex: none;
  user-select: none;
  overflow: hidden;
}

.avatar.avatar-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.message .avatar {
  width: 36px;
  height: 36px;
  font-size: 14px;
}

.list-title-row {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.list-title,
.list-sub {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.list-title {
  font-size: 15px;
  font-weight: 500;
  flex: 1;
  min-width: 0;
}

.list-sub {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 3px;
}

.time {
  color: var(--text-secondary);
  font-size: 12px;
  align-self: start;
  padding-top: 4px;
  white-space: nowrap;
}

.badge {
  min-width: 20px;
  height: 20px;
  padding: 0 6px;
  border-radius: var(--radius-full);
  background: var(--danger);
  color: #fff;
  display: inline-grid;
  place-items: center;
  font-size: 11px;
  font-weight: 600;
  flex: none;
}

.contacts-search {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line-soft);
}

.contacts-search input {
  flex: 1;
  min-width: 0;
  height: 36px;
  font-size: 14px;
}

.btn-search {
  height: 36px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
}

.btn-search:hover {
  background: var(--brand-dark);
}

.search-results:empty {
  display: none;
}

.section-label {
  margin: 12px 16px 4px;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
}

.sidebar-foot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
  background: var(--header);
  border-top: 1px solid var(--line);
  flex: none;
}

.sidebar-foot-profile {
  display: grid;
  grid-template-columns: 48px minmax(0, 1fr);
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  text-align: left;
  cursor: pointer;
}

.sidebar-foot-profile:hover .sidebar-foot-info strong {
  color: var(--brand);
}

.sidebar-foot .avatar {
  width: 48px;
  height: 48px;
  font-size: 18px;
}

.sidebar-foot-info {
  min-width: 0;
}

.sidebar-foot-info strong,
.sidebar-foot-info span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-foot-info strong {
  font-size: 15px;
  font-weight: 500;
}

.sidebar-foot-info span {
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 1px;
}

/* ── Conversation panel ── */
.conversation {
  min-width: 0;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--chat-bg);
  overflow: hidden;
}

.conversation-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  padding-top: max(8px, env(safe-area-inset-top));
  min-height: 56px;
  background: var(--header);
  border-bottom: 1px solid var(--line);
  flex: none;
  z-index: 2;
}

.conversation-head-main {
  min-width: 0;
  flex: 1;
}

.conversation-head h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.conversation-head span {
  display: block;
  color: var(--text-secondary);
  font-size: 13px;
  margin-top: 1px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.chat-head-avatar {
  width: 42px;
  height: 42px;
  font-size: 16px;
}

.chat-tools {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  background: var(--surface);
  font-size: 12px;
  flex: none;
  border: 1px solid var(--line);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: var(--radius-full);
  background: #94a3b8;
  flex: none;
}

.status-dot.online {
  background: var(--accent);
}

.status-dot.connecting {
  background: #f59e0b;
  animation: pulse 1.2s ease infinite;
}

.status-dot.fallback {
  background: #f59e0b;
}

.status-dot.offline {
  background: var(--danger);
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: .4; }
}

.mobile-back {
  display: none;
}

.messages {
  min-height: 0;
  overflow: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  padding: 12px 16px 20px;
  background: var(--chat-bg);
}

.messages.empty {
  display: grid;
  place-items: center;
}

.empty-state {
  color: var(--text-secondary);
  padding: 24px 16px;
  text-align: center;
  font-size: 14px;
}

.empty-card {
  max-width: 320px;
  padding: 32px 24px;
  border-radius: var(--radius-md);
  text-align: center;
  background: rgba(255, 255, 255, .85);
  box-shadow: var(--shadow-sm);
}

.empty-icon {
  margin-bottom: 16px;
}

.empty-card strong,
.empty-card span {
  display: block;
}

.empty-card strong {
  font-size: 18px;
  font-weight: 600;
}

.empty-card span {
  margin-top: 8px;
  color: var(--text-secondary);
  font-size: 14px;
}

.message {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin: 0 0 10px;
}

.message.mine {
  justify-content: flex-end;
}

.message.mine .avatar {
  order: 2;
}

.bubble-wrap {
  max-width: min(560px, 75%);
}

.meta {
  color: var(--text-secondary);
  font-size: 12px;
  margin-bottom: 4px;
  padding: 0 4px;
}

.message.mine .meta {
  text-align: right;
}

.msg-read-status {
  margin-top: 2px;
  padding: 0 4px;
  font-size: 11px;
  line-height: 1.2;
  color: var(--text-secondary);
  text-align: right;
  user-select: none;
}

.msg-read-status.is-read {
  color: var(--brand);
}

.bubble {
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  background: var(--surface);
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}

.bubble-text {
  font-size: 15px;
}

.bubble-quote {
  margin: 0 0 6px;
  padding: 6px 10px;
  border-radius: 6px;
  border-left: 3px solid var(--brand);
  background: rgba(51, 144, 236, .08);
  color: var(--text-secondary);
  cursor: pointer;
}

.bubble-quote strong,
.bubble-quote span {
  display: block;
}

.bubble-quote strong {
  font-size: 12px;
  color: var(--brand);
  margin-bottom: 2px;
}

.bubble-quote span {
  font-size: 13px;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: pre-wrap;
}

.message.mine .bubble {
  background: var(--mine);
  color: var(--mine-text);
  border-radius: var(--radius-sm);
  box-shadow: none;
}

.message.mine .bubble-quote {
  background: rgba(0, 0, 0, .05);
  border-left-color: #7cb342;
  color: var(--text-secondary);
}

.message.mine .bubble-quote strong {
  color: #558b2f;
}

/* ── Composer ── */
.composer-dock {
  background: var(--header);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
  position: relative;
  z-index: 5;
  flex: none;
}

.quote-bar {
  display: flex;
  align-items: stretch;
  gap: 10px;
  padding: 8px 12px 0;
  max-height: 72px;
  overflow: hidden;
}

.quote-bar-accent {
  width: 3px;
  border-radius: 3px;
  background: var(--brand);
  flex: none;
}

.quote-bar-content {
  min-width: 0;
  flex: 1;
}

.quote-bar-content strong,
.quote-bar-content span {
  display: block;
  overflow: hidden;
}

.quote-bar-content strong {
  color: var(--brand);
  font-size: 13px;
  font-weight: 500;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.quote-bar-content span {
  color: var(--text-secondary);
  font-size: 13px;
  line-height: 1.35;
  margin-top: 2px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow-wrap: anywhere;
}

.composer {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 8px 12px 10px;
}

.composer-input-wrap {
  flex: 1;
  min-width: 0;
  position: relative;
  background: var(--surface);
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  padding: 2px 0;
}

.composer textarea {
  width: 100%;
  min-height: 40px;
  max-height: 38vh;
  height: 40px;
  resize: none;
  overflow-y: hidden;
  border: 0;
  border-radius: var(--radius-lg);
  padding: 9px 14px;
  outline: none;
  line-height: 1.45;
  font-size: 16px;
  background: transparent;
}

.composer-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  color: var(--text-secondary);
  display: grid;
  place-items: center;
  flex: none;
  transition: background var(--transition), color var(--transition);
}

.composer-icon:hover:not(:disabled) {
  background: var(--sidebar-hover);
  color: var(--brand);
}

.composer-send {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-full);
  background: var(--brand);
  color: #fff;
  display: grid;
  place-items: center;
  flex: none;
  transition: background var(--transition), opacity var(--transition);
}

.composer-send:hover:not(:disabled) {
  background: var(--brand-dark);
}

.composer-send:disabled,
.composer-icon:disabled,
.composer textarea:disabled,
.voice-hold-btn:disabled {
  opacity: .45;
  cursor: not-allowed;
}

.voice-hold-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 40px;
  margin: 0;
  padding: 8px 12px;
  border: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 500;
  letter-spacing: .04em;
  cursor: pointer;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

.voice-hold-btn.holding,
.voice-hold-btn:active:not(:disabled) {
  background: rgba(0, 0, 0, .06);
}

.composer.voice-mode .composer-send {
  visibility: hidden;
  pointer-events: none;
}

.composer-icon .icon-keyboard,
.composer-icon .icon-voice {
  display: block;
}

.bubble.bubble-voice {
  padding: 0;
  background: transparent;
  box-shadow: none;
  overflow: visible;
}

.bubble.bubble-voice:has(.bubble-quote) {
  padding: 8px 12px;
  background: var(--surface);
}

.message.mine .bubble.bubble-voice {
  background: transparent;
}

.message.mine .bubble.bubble-voice:has(.bubble-quote) {
  background: var(--mine);
}

.voice-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

.message.mine .voice-row {
  flex-direction: row-reverse;
}

.voice-bubble {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  min-width: 72px;
  max-width: 220px;
  padding: 8px 14px;
  border: 0;
  border-radius: var(--radius-sm);
  background: var(--surface);
  color: var(--text);
  font: inherit;
  cursor: pointer;
  text-align: left;
  touch-action: manipulation;
}

.message.mine .voice-bubble {
  flex-direction: row-reverse;
  background: var(--mine);
  color: var(--mine-text);
  text-align: right;
}

.voice-bubble:hover {
  filter: brightness(.98);
}

.voice-icon {
  display: flex;
  flex: none;
  color: inherit;
}

.message:not(.mine) .voice-icon {
  transform: scaleX(-1);
}

.voice-waves {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 14px;
  flex: 1;
  min-width: 18px;
}

.voice-waves i {
  display: block;
  width: 3px;
  border-radius: 2px;
  background: currentColor;
  opacity: .55;
  transform-origin: center bottom;
}

.voice-waves i:nth-child(1) { height: 6px; }
.voice-waves i:nth-child(2) { height: 12px; }
.voice-waves i:nth-child(3) { height: 8px; }

.voice-bubble.playing .voice-waves i {
  animation: voice-bar 0.8s ease-in-out infinite;
}

.voice-bubble.playing .voice-waves i:nth-child(2) {
  animation-delay: .15s;
}

.voice-bubble.playing .voice-waves i:nth-child(3) {
  animation-delay: .3s;
}

@keyframes voice-bar {
  0%, 100% { transform: scaleY(.45); opacity: .45; }
  50% { transform: scaleY(1); opacity: .9; }
}

.voice-duration-out {
  flex: none;
  font-size: 12px;
  line-height: 1;
  color: var(--text-secondary);
  font-variant-numeric: tabular-nums;
  user-select: none;
}

.voice-record-overlay {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  background: rgba(0, 0, 0, .18);
}

.voice-record-overlay.hidden {
  display: none;
}

.voice-record-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  min-width: 168px;
  padding: 28px 32px 22px;
  border-radius: 16px;
  background: rgba(0, 0, 0, .72);
  color: #fff;
  box-shadow: var(--shadow-md);
  transition: background .15s ease;
}

.voice-record-overlay.cancel .voice-record-panel {
  background: rgba(196, 48, 43, .88);
}

.voice-record-icon {
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, .12);
  color: #fff;
}

.voice-record-overlay.cancel .voice-record-icon {
  background: rgba(255, 255, 255, .18);
}

.voice-record-waves {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  gap: 4px;
  height: 28px;
}

.voice-record-waves span {
  display: block;
  width: 4px;
  height: 10px;
  border-radius: 2px;
  background: #07c160;
  transition: height .08s linear;
}

.voice-record-waves.pulse span {
  animation: voice-bar 0.7s ease-in-out infinite;
}

.voice-record-waves.pulse span:nth-child(2) { animation-delay: .08s; }
.voice-record-waves.pulse span:nth-child(3) { animation-delay: .16s; }
.voice-record-waves.pulse span:nth-child(4) { animation-delay: .24s; }
.voice-record-waves.pulse span:nth-child(5) { animation-delay: .32s; }

.voice-record-waves span:nth-child(1) { height: 10px; }
.voice-record-waves span:nth-child(2) { height: 18px; }
.voice-record-waves span:nth-child(3) { height: 26px; }
.voice-record-waves span:nth-child(4) { height: 16px; }
.voice-record-waves span:nth-child(5) { height: 12px; }

.voice-record-overlay.cancel .voice-record-waves span {
  background: #fff;
}

.voice-record-hint {
  font-size: 13px;
  letter-spacing: .02em;
  opacity: .92;
}

.voice-record-overlay.cancel .voice-record-hint {
  opacity: 1;
}

.voice-record-time {
  font-size: 15px;
  opacity: .8;
  font-variant-numeric: tabular-nums;
}

body.voice-recording {
  user-select: none;
  -webkit-user-select: none;
  overscroll-behavior: none;
}

.message-media {
  display: block;
  max-width: min(320px, 70vw);
}

.message-media img,
.message-media video {
  display: block;
  max-width: 100%;
  max-height: 360px;
  border-radius: var(--radius-sm);
  background: rgba(0, 0, 0, .06);
}

.message-media video {
  width: min(320px, 70vw);
}

.media-name {
  display: block;
  max-width: min(320px, 70vw);
  margin-top: 4px;
  color: inherit;
  font-size: 12px;
  opacity: .7;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  text-decoration: none;
}

.message-location {
  max-width: min(280px, 72vw);
}

.location-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: rgba(7, 193, 96, .08);
  color: inherit;
  text-decoration: none;
  border: 1px solid rgba(7, 193, 96, .18);
}

.message.mine .location-card {
  background: rgba(255, 255, 255, .14);
  border-color: rgba(255, 255, 255, .22);
}

.location-pin {
  flex: 0 0 auto;
  color: #07c160;
  margin-top: 1px;
}

.message.mine .location-pin {
  color: #fff;
}

.location-body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.location-title {
  font-size: 14px;
  font-weight: 600;
  line-height: 1.35;
}

.location-address,
.location-coords {
  font-size: 12px;
  opacity: .78;
  line-height: 1.4;
  overflow: hidden;
  text-overflow: ellipsis;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

.location-coords {
  opacity: .55;
  -webkit-line-clamp: 1;
}

.admin-link-btn {
  color: #2f80ed;
  text-decoration: none;
  font-size: 12px;
}

.admin-link-btn:hover {
  text-decoration: underline;
}

/* ── Profile sheet ── */
.profile-mask {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, .45);
  display: grid;
  place-items: center;
  padding: 20px;
}

.profile-sheet {
  width: min(420px, 100%);
  max-height: calc(100vh - 40px);
  overflow: auto;
  background: var(--surface);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg, 0 18px 48px rgba(0, 0, 0, .18));
}

.profile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  border-bottom: 1px solid var(--line);
}

.profile-head h2 {
  margin: 0;
  font-size: 18px;
}

.profile-body {
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.profile-avatar-block {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.profile-avatar-preview {
  width: 88px;
  height: 88px;
  font-size: 32px;
}

.profile-avatar-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-secondary,
.btn-text,
.profile-save {
  min-height: 40px;
  padding: 0 16px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}

.btn-secondary {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--text);
}

.btn-secondary:hover {
  border-color: var(--brand);
  color: var(--brand);
}

.btn-text {
  border: 0;
  background: transparent;
  color: var(--text-secondary);
}

.btn-text:hover {
  color: var(--brand);
}

.profile-field {
  margin: 0;
}

.profile-color-block {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-label {
  font-size: 13px;
  color: var(--text-secondary);
}

.profile-color-options {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.profile-color {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-full);
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}

.profile-color.active {
  border-color: var(--text);
  box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px currentColor;
}

.profile-save {
  width: 100%;
  border: 0;
  background: var(--brand);
  color: #fff;
}

.profile-save:hover:not(:disabled) {
  background: var(--brand-dark);
}

.profile-save:disabled {
  opacity: .6;
  cursor: not-allowed;
}

/* ── Context menu & toast ── */
.msg-menu-mask {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: transparent;
}

.msg-menu {
  position: fixed;
  z-index: 81;
  display: flex;
  overflow: hidden;
  border-radius: var(--radius-sm);
  background: rgba(38, 42, 48, .96);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.msg-menu button {
  min-width: 72px;
  height: 44px;
  padding: 0 16px;
  background: transparent;
  color: #fff;
  font-size: 14px;
}

.msg-menu button + button {
  border-left: 1px solid rgba(255, 255, 255, .1);
}

.msg-menu button:hover,
.msg-menu button:active {
  background: rgba(255, 255, 255, .08);
}

.app-toast {
  position: fixed;
  left: 50%;
  bottom: max(80px, calc(env(safe-area-inset-bottom) + 60px));
  z-index: 90;
  transform: translateX(-50%);
  padding: 10px 20px;
  border-radius: var(--radius-full);
  background: rgba(0, 0, 0, .78);
  color: #fff;
  font-size: 14px;
  pointer-events: none;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

/* ── Admin panel ── */
.admin-shell {
  width: min(1280px, calc(100vw - 32px));
  min-height: calc(100vh - 32px);
  margin: 16px auto;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  overflow: hidden;
  background: #fff;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-md);
}

.admin-nav {
  background: #17212b;
  color: #fff;
  padding: 24px 16px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.admin-nav h1 {
  margin: 0 0 4px;
  font-size: 20px;
  font-weight: 600;
}

.admin-nav p {
  margin: 0;
  color: #8b9bab;
  font-size: 13px;
}

.admin-nav nav {
  display: grid;
  gap: 4px;
}

.admin-tab,
.admin-nav a {
  min-height: 42px;
  border-radius: var(--radius-sm);
  padding: 0 12px;
  display: flex;
  align-items: center;
  color: #c5cdd5;
  background: transparent;
  text-align: left;
  text-decoration: none;
  font-size: 14px;
  transition: background var(--transition);
}

.admin-tab.active,
.admin-tab:hover,
.admin-nav a:hover {
  background: rgba(255, 255, 255, .08);
  color: #fff;
}

.admin-tab.active {
  background: rgba(51, 144, 236, .25);
  color: #fff;
}

.admin-main {
  min-width: 0;
  padding: 20px;
  background: #f4f6f8;
  position: relative;
}

.admin-top {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 16px;
}

.stat {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 16px;
}

.stat strong {
  display: block;
  font-size: 26px;
  font-weight: 600;
  color: var(--brand);
}

.stat span {
  color: var(--text-secondary);
  font-size: 13px;
}

.admin-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.admin-toolbar {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 88px;
  gap: 10px;
  padding: 14px;
  border-bottom: 1px solid var(--line);
}

.admin-toolbar input,
.admin-toolbar select,
.admin-toolbar button,
.contacts-search input {
  height: 38px;
}

.admin-toolbar select {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 0 10px;
  background: #fff;
}

#adminLocations .admin-toolbar {
  grid-template-columns: minmax(140px, 220px) minmax(0, 1fr) 88px;
}

.admin-toolbar button,
.row-actions button {
  height: 38px;
  border-radius: var(--radius-sm);
  background: var(--brand);
  color: #fff;
  font-size: 14px;
}

.admin-toolbar button:hover,
.row-actions button:hover {
  background: var(--brand-dark);
}

.admin-create-bar {
  grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr) minmax(0, 1fr) auto auto;
  border-bottom: none;
}

.admin-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  color: var(--text-secondary);
  font-size: 14px;
  user-select: none;
}

.table-wrap {
  overflow: auto;
}

table {
  width: 100%;
  min-width: 820px;
  border-collapse: collapse;
}

th,
td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
  font-size: 14px;
}

th {
  color: var(--text-secondary);
  background: #fafbfc;
  font-weight: 600;
  font-size: 13px;
}

td span {
  color: var(--text-secondary);
  font-size: 12px;
}

.admin-input {
  height: 34px;
}

.color-input {
  max-width: 110px;
}

.message-cell {
  max-width: 420px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.row-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.row-actions button {
  height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.row-actions .danger {
  background: var(--danger);
}

.row-actions .danger:hover {
  background: #c62828;
}

.row-actions .subtle {
  background: #78909c;
}

.admin-toast {
  position: fixed;
  right: 24px;
  bottom: 24px;
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  color: #fff;
  background: #17212b;
  box-shadow: var(--shadow-md);
  font-size: 14px;
}

/* ── Tablet ── */
@media (max-width: 1024px) {
  :root {
    --sidebar-w: clamp(280px, 36vw, 360px);
  }

  .bubble-wrap {
    max-width: min(480px, 78%);
  }
}

/* ── Mobile (WeChat-style single panel) ── */
@media (max-width: 768px) {
  .chat-shell {
    display: block;
    position: relative;
    height: 100%;
  }

  .sidebar,
  .conversation {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
  }

  .conversation {
    display: none;
  }

  .chat-shell.chat-open .sidebar {
    display: none;
  }

  .chat-shell.chat-open .conversation {
    display: grid;
  }

  .conversation.keyboard-open {
    top: 0;
    right: 0;
    bottom: var(--keyboard-inset, 0px);
    left: 0;
    height: auto;
  }

  .conversation.keyboard-open .messages {
    scroll-padding-bottom: 12px;
  }

  .sidebar-head {
    padding: 6px 8px;
    padding-top: max(6px, env(safe-area-inset-top));
    min-height: 52px;
  }

  .sidebar-search {
    height: 34px;
    font-size: 16px;
  }

  .tab-bar .tab {
    height: 42px;
  }

  .list-item {
    min-height: 68px;
    padding: 8px 10px;
    grid-template-columns: 50px minmax(0, 1fr) auto;
  }

  .avatar {
    width: 50px;
    height: 50px;
    font-size: 18px;
  }

  .sidebar-foot .avatar {
    width: 44px;
    height: 44px;
    font-size: 16px;
  }

  .mobile-back {
    display: grid;
    place-items: center;
  }

  .conversation-head {
    padding: 6px 10px;
    padding-top: max(6px, env(safe-area-inset-top));
    min-height: 52px;
  }

  .chat-tools {
    font-size: 11px;
    padding: 3px 8px;
  }

  .messages {
    padding: 8px 10px 16px;
  }

  .bubble-wrap {
    max-width: 82%;
  }

  .composer {
    padding: 6px 8px 8px;
    gap: 6px;
  }

  .composer-icon,
  .composer-send {
    width: 40px;
    height: 40px;
  }

  .composer textarea {
    min-height: 38px;
    font-size: 16px;
  }

  .message-media,
  .message-media video,
  .media-name {
    max-width: 75vw;
  }

  .admin-shell {
    width: 100%;
    min-height: 100%;
    height: 100%;
    margin: 0;
    grid-template-columns: 1fr;
    border-radius: 0;
    overflow: auto;
    overscroll-behavior: contain;
  }

  .admin-nav {
    padding: 16px;
    gap: 14px;
    padding-top: max(16px, env(safe-area-inset-top));
  }

  .admin-nav nav {
    grid-template-columns: repeat(2, 1fr);
  }

  .admin-top {
    grid-template-columns: repeat(2, 1fr);
  }

  .admin-main {
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
  }
}

@media (max-width: 480px) {
  .auth-panel,
  .install-box {
    padding: 28px 20px 24px;
  }

  .contacts-search,
  .admin-toolbar,
  .admin-create-bar {
    grid-template-columns: 1fr;
    flex-direction: column;
  }

  .contacts-search {
    display: grid;
  }

  .admin-top {
    grid-template-columns: 1fr 1fr;
  }

  .chat-head-avatar {
    display: none !important;
  }
}

/* ── Desktop wide ── */
@media (min-width: 769px) {
  .chat-shell:not(.chat-open) .conversation {
    display: grid;
  }

  .chat-shell.chat-open .sidebar {
    display: grid;
  }
}

/* ── Presence status ── */
.avatar-wrap {
  position: relative;
  width: 54px;
  height: 54px;
  flex: none;
}

.avatar-wrap .avatar {
  width: 100%;
  height: 100%;
}

.message .avatar-wrap {
  width: 36px;
  height: 36px;
}

.presence-dot {
  position: absolute;
  right: 0;
  bottom: 0;
  width: 12px;
  height: 12px;
  border-radius: var(--radius-full);
  border: 2px solid var(--sidebar);
  background: #b2b2b2;
}

.presence-dot.online {
  background: #07c160;
}

.presence-dot.away {
  background: #fa9d3b;
}

.presence-dot.offline {
  background: #b2b2b2;
}

.presence-text {
  color: var(--text-secondary);
  font-size: 13px;
}

.presence-text.online {
  color: #07c160;
}

.presence-text.away {
  color: #fa9d3b;
}

.presence-text.offline {
  color: var(--text-secondary);
}

.list-presence {
  margin-right: 6px;
  font-size: 12px;
}

.list-presence.online {
  color: #07c160;
}

.list-presence.away {
  color: #fa9d3b;
}

.list-presence.offline {
  color: var(--text-secondary);
}

@media (max-width: 768px) {
  .avatar-wrap {
    width: 50px;
    height: 50px;
  }
}

/* ── Reduced motion ── */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: .01ms !important;
    transition-duration: .01ms !important;
  }
}
