:root {
  --bg: #dfe4df;
  --panel: #f7f7f4;
  --line: #d6d9d3;
  --text: #1f2622;
  --muted: #6a746e;
  --wechat: #95ec69;
  --wechat-deep: #2f7d32;
  --white: #ffffff;
  --danger: #c94a43;
  --shadow: 0 18px 50px rgba(35, 43, 37, 0.18);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
}

body {
  margin: 0;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", sans-serif;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
  background:
    radial-gradient(circle at top left, rgba(255, 255, 255, 0.72), transparent 32rem),
    linear-gradient(145deg, #d7ded8, #eff1ec);
}

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

input,
textarea {
  user-select: text !important;
  -webkit-user-select: text !important;
  -webkit-touch-callout: default !important;
}

.phone-shell {
  width: min(100vw, 1200px);
  height: calc(100dvh - 28px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 18px;
  padding: 18px 18px 8px;
  overscroll-behavior: none;
}

.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 4;
  display: flex;
  height: 28px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 0 10px;
  color: rgba(31, 38, 34, 0.62);
  font-size: 12px;
  background: rgba(247, 247, 244, 0.72);
  backdrop-filter: blur(8px);
}

.site-footer a {
  color: inherit;
  text-decoration: none;
}

.site-footer a:hover {
  text-decoration: underline;
}

.chat-screen,
.drawer {
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(28, 37, 32, 0.1);
  background: rgba(247, 247, 244, 0.94);
  box-shadow: var(--shadow);
}

.chat-screen {
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr) auto;
  border-radius: 8px;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
}

.topbar {
  display: grid;
  grid-template-columns: 36px minmax(0, 1fr) 36px;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-bottom: 1px solid var(--line);
  background: #ededeb;
}

.topbar::after {
  content: "";
}

.icon-button {
  width: 30px;
  height: 30px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--text);
  font-size: 19px;
  cursor: pointer;
}

.icon-button:hover {
  background: rgba(0, 0, 0, 0.06);
}

.partner-head {
  display: flex;
  min-width: 0;
  align-items: center;
  justify-content: center;
  gap: 10px;
}

.topbar .avatar {
  display: none;
}

.avatar {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  display: grid;
  place-items: center;
  overflow: hidden;
  border-radius: 7px;
  background: linear-gradient(135deg, #33413b, #789084);
  color: #fff;
  font-weight: 700;
}

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

.avatar-spacer {
  visibility: hidden;
}

.partner-name {
  font-size: 17px;
  font-weight: 700;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.partner-status {
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.provider-select {
  max-width: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  padding: 7px 10px;
}

.message-list {
  overflow-y: auto;
  padding: 8px 10px 10px;
  touch-action: pan-y;
  overscroll-behavior: contain;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
  background:
    linear-gradient(rgba(219, 225, 219, 0.9), rgba(219, 225, 219, 0.9)),
    repeating-linear-gradient(135deg, transparent 0 12px, rgba(255, 255, 255, 0.2) 12px 13px);
}

.empty-state {
  max-width: 520px;
  margin: 12vh auto 0;
  color: var(--muted);
  text-align: center;
  line-height: 1.8;
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: 7px;
  margin: 6px 0;
  touch-action: pan-y;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
}

.message-row.user {
  justify-content: flex-end;
}

.message-row.typing {
  margin-top: 8px;
}

.message-row.user .avatar {
  order: 2;
  background: linear-gradient(135deg, #b37272, #e3a088);
}

.bubble {
  max-width: min(70%, 640px);
  padding: 8px 10px;
  border-radius: 7px;
  background: var(--white);
  font-size: 15px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  position: relative;
  touch-action: pan-y;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
  -webkit-user-drag: none;
}

.bubble *,
.message-row img {
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
  -webkit-user-drag: none;
}

.message-text {
  display: inline;
  pointer-events: none;
  user-select: none !important;
  -webkit-user-select: none !important;
  -webkit-touch-callout: none !important;
}

.message-text::before {
  content: attr(data-text);
  white-space: pre-wrap;
}

.message-row.user .bubble {
  background: var(--wechat);
}

.message-image {
  display: block;
  width: min(240px, 100%);
  max-height: 300px;
  margin-bottom: 7px;
  border-radius: 8px;
  object-fit: cover;
  background: rgba(255, 255, 255, 0.5);
}

.message-image:only-child {
  margin-bottom: 0;
}

.typing-bubble {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 76px;
  height: 38px;
  max-width: none;
  padding: 0 14px;
  user-select: none;
  -webkit-user-select: none;
}

.typing-dots {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  gap: 5px;
  width: 34px;
  height: 10px;
}

.typing-dots i {
  display: block;
  flex: 0 0 6px;
  width: 6px;
  height: 6px;
  border-radius: 999px;
  background: rgba(31, 38, 34, 0.46);
  animation: typingPulse 1.15s ease-in-out infinite;
}

.typing-dots i:nth-child(2) {
  animation-delay: 0.16s;
}

.typing-dots i:nth-child(3) {
  animation-delay: 0.32s;
}

@keyframes typingPulse {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.38;
  }

  40% {
    transform: translateY(-3px);
    opacity: 0.9;
  }
}

.time-divider {
  width: fit-content;
  max-width: 82%;
  margin: 9px auto 6px;
  padding: 2px 7px;
  border-radius: 6px;
  background: rgba(100, 110, 104, 0.26);
  color: rgba(31, 38, 34, 0.72);
  font-size: 12px;
  line-height: 1.5;
}

.history-loader {
  display: block;
  width: fit-content;
  max-width: 82%;
  margin: 2px auto 14px;
  padding: 4px 9px;
  border: 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.44);
  color: rgba(31, 38, 34, 0.58);
  cursor: pointer;
  font-size: 12px;
  line-height: 1.5;
}

.meta {
  margin-top: 4px;
  color: rgba(31, 38, 34, 0.55);
  font-size: 11px;
}

.composer {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 32px auto;
  align-items: end;
  gap: 5px;
  padding: 4px 8px calc(4px + env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: #f4f4f1;
}

.composer textarea {
  order: 1;
  min-height: 34px;
  max-height: 96px;
  resize: none;
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 6px 9px;
  outline: none;
  background: var(--white);
}

.send-button,
.composer-tool,
.primary-wide,
.secondary-wide,
.danger-wide,
.password-card button {
  border: 0;
  border-radius: 8px;
  padding: 0 18px;
  background: var(--wechat-deep);
  color: white;
  cursor: pointer;
  font-weight: 700;
}

.composer-tool {
  width: 32px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--text);
  font-size: 19px;
  line-height: 1;
}

#imageButton {
  order: 2;
  font-size: 24px;
  font-weight: 400;
}

.send-button {
  order: 3;
  height: 34px;
  min-width: 50px;
  padding: 0 10px;
  font-size: 14px;
  align-self: end;
}

.send-button:disabled {
  opacity: 0.55;
  cursor: default;
}

.hidden-file-input {
  display: none;
}

.image-preview {
  order: 0;
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  gap: 9px;
  width: fit-content;
  max-width: 100%;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
}

.image-preview.hidden {
  display: none;
}

.image-preview img {
  width: 54px;
  height: 54px;
  border-radius: 7px;
  object-fit: cover;
}

.image-preview span {
  max-width: min(58vw, 260px);
  overflow: hidden;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-preview button {
  width: 28px;
  height: 28px;
  border: 0;
  border-radius: 999px;
  background: #e4e4df;
  color: var(--text);
  cursor: pointer;
}

.drawer {
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
  border-radius: 8px;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px;
  border-bottom: 1px solid var(--line);
}

.drawer-title {
  font-size: 18px;
  font-weight: 800;
}

.drawer-subtitle {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.tabs {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 10px;
  gap: 8px;
  border-bottom: 1px solid var(--line);
}

.tab {
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  padding: 9px 6px;
  cursor: pointer;
}

.tab.active {
  border-color: var(--line);
  background: var(--white);
  font-weight: 700;
}

.tab-panel {
  display: none;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
}

.tab-panel.active {
  display: block;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.compact-grid {
  grid-template-columns: 1fr 1fr;
}

label,
.field-block {
  color: var(--muted);
  font-size: 13px;
}

.field-block {
  display: block;
  margin-top: 14px;
}

input,
textarea,
select {
  width: 100%;
  margin-top: 6px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--text);
  padding: 9px 10px;
  outline: none;
}

textarea {
  resize: vertical;
  line-height: 1.55;
}

.avatar-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.avatar-picker {
  display: block;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.55);
}

.toggle-line {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--text);
}

.toggle-line input {
  width: 18px;
  height: 18px;
  margin: 0;
}

.settings-block {
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.settings-block .toggle-line {
  margin-top: 0;
}

.inline-number-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 10px;
  font-weight: 800;
}

.inline-number-field input {
  flex: 0 0 88px;
  width: 88px;
  text-align: center;
}

.section-title {
  margin-bottom: 10px;
  color: var(--text);
  font-size: 14px;
  font-weight: 800;
}

.hint-text {
  margin-top: 10px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
}

.primary-wide,
.secondary-wide,
.danger-wide {
  width: 100%;
  min-height: 42px;
  margin-top: 14px;
}

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

.danger-wide {
  background: var(--danger);
}

.status-panel {
  margin-top: 14px;
  padding: 12px;
  border-radius: 8px;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.7;
  font-size: 13px;
}

.voice-upload {
  margin-top: 14px;
}

.speak-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 16px;
  margin-left: 5px;
  padding: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: rgba(31, 38, 34, 0.45);
  vertical-align: -1px;
  cursor: pointer;
}

.speak-bars {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  height: 14px;
}

.speak-bars i {
  display: block;
  width: 2px;
  border-radius: 999px;
  background: currentColor;
}

.speak-bars i:nth-child(1) {
  height: 7px;
}

.speak-bars i:nth-child(2) {
  height: 13px;
}

.speak-bars i:nth-child(3) {
  height: 9px;
}

.speak-button.playing {
  color: var(--wechat-deep);
}

.speak-button.playing .speak-bars i {
  animation: speakWave 0.72s ease-in-out infinite;
}

.speak-button.playing .speak-bars i:nth-child(2) {
  animation-delay: 0.12s;
}

.speak-button.playing .speak-bars i:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes speakWave {
  0%,
  100% {
    transform: scaleY(0.55);
    opacity: 0.45;
  }

  45% {
    transform: scaleY(1.25);
    opacity: 1;
  }
}

.speak-button.loading {
  opacity: 0.6;
  cursor: default;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 22px;
  transform: translateX(-50%) translateY(20px);
  max-width: min(90vw, 520px);
  border-radius: 8px;
  background: rgba(31, 38, 34, 0.9);
  color: white;
  padding: 10px 14px;
  opacity: 0;
  pointer-events: none;
  transition: 0.2s ease;
  z-index: 20;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.message-action-menu {
  position: fixed;
  z-index: 25;
  display: flex;
  align-items: center;
  min-width: 0;
  padding: 3px 6px;
  border: 1px solid rgba(28, 37, 32, 0.14);
  border-radius: 7px;
  background: rgba(31, 38, 34, 0.94);
  box-shadow: 0 10px 24px rgba(35, 43, 37, 0.24);
}

.message-action-menu.hidden {
  display: none;
}

.message-action-menu button {
  min-width: 46px;
  min-height: 30px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: #fff;
  cursor: pointer;
  font-size: 13px;
  white-space: nowrap;
}

.message-action-menu button + button {
  border-left: 1px solid rgba(255, 255, 255, 0.28);
  border-radius: 0;
}

.message-action-menu button:hover {
  background: rgba(255, 255, 255, 0.12);
}

.avatar-crop-mask {
  position: fixed;
  inset: 0;
  z-index: 35;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(20, 25, 22, 0.48);
}

.avatar-crop-mask.hidden {
  display: none;
}

.avatar-crop-card {
  width: min(92vw, 390px);
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.avatar-crop-title {
  margin-bottom: 12px;
  font-size: 17px;
  font-weight: 800;
  text-align: center;
}

#avatarCropCanvas {
  display: block;
  width: min(74vw, 320px);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  margin: 0 auto;
  border-radius: 8px;
  background: #eef0ec;
  touch-action: none;
}

#avatarCropZoom {
  margin-top: 14px;
}

.avatar-crop-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.avatar-crop-actions button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  color: var(--text);
  cursor: pointer;
  font-weight: 700;
}

.avatar-crop-actions button:last-child {
  border: 0;
  background: var(--wechat-deep);
  color: #fff;
}

.password-mask {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(223, 228, 223, 0.38);
  backdrop-filter: blur(2px);
  z-index: 30;
}

.password-mask.hidden {
  display: none;
}

html.has-saved-password .password-mask {
  display: none;
}

body.auth-locked .phone-shell {
  visibility: visible;
  pointer-events: none;
}

body.auth-locked .message-list {
  background: rgba(223, 228, 223, 0.52);
}

.password-card {
  width: min(92vw, 360px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.password-card h1 {
  margin: 0 0 8px;
  font-size: 20px;
}

.password-card p {
  margin: 0 0 16px;
  color: var(--muted);
}

.password-card button {
  width: 100%;
  height: 42px;
  margin-top: 12px;
}

@media (max-width: 860px) {
  .phone-shell {
    display: block;
    width: 100vw;
    height: calc(100dvh - 26px);
    padding: 0;
  }

  .chat-screen {
    height: calc(100dvh - 26px);
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }

  .site-footer {
    height: 26px;
    font-size: 11px;
  }

  .drawer {
    position: fixed;
    inset: 0;
    z-index: 10;
    border-radius: 0;
    transform: translateX(100%);
    transition: transform 0.2s ease;
  }

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

  .provider-select {
    max-width: 132px;
  }

  .message-list {
    padding: 7px 9px 9px;
  }

  .bubble {
    max-width: 68vw;
  }
}
