:root {
  color-scheme: light;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #1f2329;
  background: #eef0f2;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

* {
  box-sizing: border-box;
}

html,
body {
  min-width: 320px;
  min-height: 100%;
  margin: 0;
}

body {
  min-height: 100vh;
  background:
    linear-gradient(180deg, #f7f8f9 0, #eef0f2 24%, #e6e8eb 100%);
}

button {
  font: inherit;
}

.chat-shell {
  position: relative;
  display: flex;
  flex-direction: column;
  width: 100%;
  min-height: 100vh;
  margin: 0;
  overflow: hidden;
  background: #f2f3f5;
  box-shadow: none;
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  min-height: 78px;
  padding: 10px max(18px, 3vw);
  border-bottom: 1px solid rgb(31 35 41 / 7%);
  background: rgb(248 249 250 / 90%);
  backdrop-filter: blur(18px);
}

.icon-button,
.modal-close,
.customer-service,
.group-number,
.group-edit-trigger {
  border: 0;
  cursor: pointer;
}

.icon-button {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  padding: 0;
  color: #17191d;
  background: transparent;
}

.icon-button svg {
  width: 27px;
  height: 27px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.9;
}

.back-button {
  justify-self: start;
}

.more-button {
  justify-self: end;
}

.more-button svg {
  width: 30px;
  height: 30px;
  stroke-width: 3.2;
}

.chat-title {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
  line-height: 1.15;
}

.chat-title strong {
  font-size: clamp(18px, 2vw, 23px);
  letter-spacing: 0;
}

.chat-content {
  flex: 1;
  width: 100%;
  margin: 0;
  padding: clamp(28px, 5vw, 66px) clamp(16px, 3vw, 32px) clamp(92px, 8vw, 124px) clamp(12px, 2vw, 24px);
}

.message-row {
  display: flex;
  align-items: flex-start;
  gap: clamp(10px, 1.8vw, 18px);
  margin-bottom: 24px;
}

.avatar {
  flex: 0 0 auto;
  width: clamp(42px, 5vw, 54px);
  height: clamp(42px, 5vw, 54px);
  border-radius: 10px;
  object-fit: cover;
  background: #f7fce9;
  box-shadow: 0 4px 12px rgb(55 65 81 / 8%);
}

.message-bubble {
  position: relative;
  max-width: min(760px, calc(100% - 68px));
  padding: clamp(20px, 3vw, 34px) clamp(20px, 3.7vw, 44px);
  border-radius: 5px 18px 18px 18px;
  background: #fff;
  box-shadow: 0 8px 22px rgb(31 35 41 / 5%);
  color: #20242a;
}

.message-bubble::before {
  position: absolute;
  top: 18px;
  left: -9px;
  width: 17px;
  height: 17px;
  background: #fff;
  content: "";
  clip-path: polygon(100% 0, 100% 100%, 0 0);
}

.message-bubble p {
  position: relative;
  margin: 0 0 19px;
  font-size: clamp(16px, 1.7vw, 20px);
  line-height: 1.75;
  letter-spacing: 0;
}

.message-bubble p:last-child {
  margin-bottom: 0;
}

.group-number {
  display: inline-block;
  padding: 0 2px;
  color: #e02424;
  font-weight: 700;
  text-decoration: underline;
  text-decoration-color: rgb(224 36 36 / 38%);
  text-underline-offset: 3px;
  background: transparent;
}

.group-number-line {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 3px;
}

.group-edit-trigger {
  display: inline-grid;
  width: 25px;
  height: 25px;
  place-items: center;
  padding: 0;
  border-radius: 6px;
  color: #7d8792;
  background: transparent;
}

.group-edit-trigger:hover {
  color: #2f7fc6;
  background: #eef5fb;
}

.group-edit-trigger svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.group-number:focus-visible {
  border-radius: 4px;
  outline: 3px solid rgb(55 136 221 / 26%);
  outline-offset: 3px;
}

.video-heading {
  padding-top: 5px;
  color: #414751;
  font-weight: 600;
  text-align: center;
}

.media-row {
  margin-bottom: 26px;
}

.video-message {
  width: min(340px, calc(100% - 68px));
  overflow: hidden;
  border-radius: 5px 16px 16px 16px;
  background: #fff;
  box-shadow: 0 8px 22px rgb(31 35 41 / 7%);
}

.tutorial-video {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  max-height: 520px;
  background: #dfe3e6;
  object-fit: cover;
}

.video-caption {
  display: block;
  padding: 9px 13px 11px;
  color: #68717c;
  font-size: 12px;
}

.closing-row {
  margin-bottom: 0;
}

.closing-bubble {
  padding-top: 18px;
  padding-bottom: 18px;
}

.closing-bubble p {
  margin-bottom: 9px;
  font-size: clamp(15px, 1.5vw, 18px);
  line-height: 1.65;
}

.closing-bubble strong {
  color: #1e6db7;
  font-weight: 600;
}

.customer-service {
  position: fixed;
  right: clamp(14px, 2vw, 24px);
  bottom: calc(28px + env(safe-area-inset-bottom));
  z-index: 6;
  display: grid;
  width: 58px;
  height: 58px;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  color: #fff;
  background: #e8a928;
  box-shadow: 0 12px 26px rgb(190 132 15 / 28%), inset 0 0 0 3px rgb(255 255 255 / 35%);
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.customer-service:hover {
  transform: translateY(-3px);
  box-shadow: 0 15px 31px rgb(190 132 15 / 36%), inset 0 0 0 3px rgb(255 255 255 / 44%);
}

.customer-service:focus-visible,
.modal-close:focus-visible,
.icon-button:focus-visible {
  outline: 3px solid rgb(55 136 221 / 34%);
  outline-offset: 4px;
}

.customer-service svg {
  width: 28px;
  height: 28px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.6;
  transform: translateY(-4px);
}

.service-label {
  position: absolute;
  bottom: 6px;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0;
}

.service-spark {
  position: absolute;
  top: 5px;
  right: 9px;
  font-size: 12px;
  line-height: 1;
}

.toast {
  position: fixed;
  bottom: calc(96px + env(safe-area-inset-bottom));
  left: 50%;
  z-index: 15;
  padding: 9px 15px;
  border-radius: 7px;
  color: #fff;
  font-size: 13px;
  background: rgb(30 35 42 / 88%);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgb(22 27 32 / 52%);
  backdrop-filter: blur(7px);
  animation: fade-in 180ms ease both;
}

.modal-backdrop[hidden] {
  display: none;
}

.qr-modal {
  position: relative;
  width: min(100%, 390px);
  padding: 30px 28px 24px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 80px rgb(16 24 40 / 22%);
  text-align: center;
  animation: rise-in 220ms ease both;
}

.group-edit-modal {
  position: relative;
  width: min(100%, 410px);
  padding: 30px 28px 26px;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 24px 80px rgb(16 24 40 / 22%);
  animation: rise-in 220ms ease both;
}

.group-edit-modal h2 {
  margin: 0;
  font-size: 23px;
  line-height: 1.35;
}

.group-edit-modal > p {
  margin: 8px 0 22px;
  color: #747d87;
  font-size: 13px;
  line-height: 1.6;
}

.group-edit-form {
  display: grid;
  gap: 9px;
}

.group-edit-form label {
  color: #414751;
  font-size: 13px;
  font-weight: 600;
}

.group-edit-form input {
  width: 100%;
  height: 44px;
  padding: 0 12px;
  border: 1px solid #cfd5dc;
  border-radius: 8px;
  color: #20242a;
  font: inherit;
  outline: none;
}

.group-edit-form input:focus {
  border-color: #2f7fc6;
  box-shadow: 0 0 0 3px rgb(47 127 198 / 16%);
}

.group-save-button {
  height: 44px;
  margin-top: 7px;
  border: 0;
  border-radius: 8px;
  color: #fff;
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  background: #2f7fc6;
  cursor: pointer;
}

.group-save-button:disabled {
  cursor: wait;
  opacity: 0.6;
}

.group-edit-status {
  min-height: 22px;
  margin-top: 3px;
  color: #747d87;
  font-size: 13px;
  line-height: 1.5;
}

.group-edit-status.success {
  color: #287245;
}

.group-edit-status.error {
  color: #b53c3c;
}

.modal-close {
  position: absolute;
  top: 13px;
  right: 13px;
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  padding: 0;
  border-radius: 50%;
  color: #79818b;
  background: #f4f5f7;
}

.modal-close svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-width: 1.8;
}

.modal-kicker {
  margin-bottom: 7px;
  color: #b78319;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.qr-modal h2 {
  margin: 0;
  font-size: 23px;
  line-height: 1.35;
}

.qr-modal p {
  margin: 8px auto 18px;
  color: #747d87;
  font-size: 13px;
  line-height: 1.6;
}

.qr-code {
  display: block;
  width: min(100%, 290px);
  height: auto;
  margin: 0 auto 16px;
  border-radius: 8px;
  background: #fff;
}

.qr-brand {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #858c94;
  font-size: 12px;
}

.qr-brand img {
  width: 22px;
  height: 22px;
  border-radius: 5px;
}

@keyframes fade-in {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

@keyframes rise-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 640px) {
  .chat-shell {
    box-shadow: none;
  }

  .chat-header {
    grid-template-columns: 45px 1fr 45px;
    min-height: 64px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .icon-button {
    width: 38px;
    height: 38px;
  }

  .chat-content {
    padding: 26px 14px 92px 12px;
  }

  .message-row {
    gap: 9px;
    margin-bottom: 20px;
  }

  .avatar {
    width: 42px;
    height: 42px;
    border-radius: 8px;
  }

  .message-bubble {
    max-width: calc(100% - 51px);
    padding: 17px 16px;
    border-radius: 4px 14px 14px 14px;
  }

  .message-bubble::before {
    top: 14px;
    left: -7px;
    width: 14px;
    height: 14px;
  }

  .message-bubble p {
    margin-bottom: 13px;
    font-size: 15px;
    line-height: 1.7;
  }

  .video-message {
    width: min(250px, calc(100% - 51px));
    border-radius: 4px 14px 14px 14px;
  }

  .tutorial-video {
    max-height: 390px;
  }

  .customer-service {
    right: 15px;
    bottom: calc(22px + env(safe-area-inset-bottom));
    width: 52px;
    height: 52px;
  }

  .customer-service svg {
    width: 25px;
    height: 25px;
  }

  .service-label {
    bottom: 5px;
    font-size: 9px;
  }

  .toast {
    bottom: calc(82px + env(safe-area-inset-bottom));
  }

  .qr-modal {
    padding-right: 20px;
    padding-left: 20px;
  }

  .group-edit-modal {
    padding-right: 20px;
    padding-left: 20px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
  }
}
