:root {
  color-scheme: light;
  --page: #f4f6f7;
  --panel: #ffffff;
  --text: #17211d;
  --muted: #68736f;
  --line: #dce3e0;
  --green: #22c55e;
  --green-dark: #138a43;
  --ink: #0e1512;
  --wechat-bg: #ededed;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 16% 12%, rgba(34, 197, 94, 0.13), transparent 25%),
    linear-gradient(135deg, #f7faf9, var(--page));
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(360px, 480px) 1fr;
  gap: 22px;
  min-height: 100vh;
  padding: 22px;
}

.panel,
.preview-area {
  min-width: 0;
}

.panel {
  overflow: auto;
  max-height: calc(100vh - 44px);
  padding: 22px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 20px 50px rgba(20, 33, 29, 0.08);
}

.brand {
  display: flex;
  gap: 14px;
  align-items: center;
  margin-bottom: 22px;
}

.brand-mark {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border-radius: 8px;
  background: var(--green);
  color: #fff;
  font-size: 24px;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

.brand h1 {
  font-size: 22px;
  letter-spacing: 0;
}

.brand p {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.form {
  display: grid;
  gap: 18px;
}

.section {
  display: grid;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.section h2,
.history h2,
.result h2 {
  font-size: 15px;
}

.section-head,
.preview-toolbar,
.result-head,
.result-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

label {
  display: grid;
  gap: 7px;
}

label span {
  color: var(--muted);
  font-size: 12px;
}

input,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--text);
  outline: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}

input {
  height: 40px;
  padding: 0 12px;
}

textarea {
  min-height: 74px;
  resize: vertical;
  padding: 10px 12px;
  line-height: 1.5;
}

input:focus,
textarea:focus {
  border-color: rgba(34, 197, 94, 0.85);
  box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.14);
}

.actions {
  display: flex;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  background: transparent;
}

button,
.link-button {
  height: 40px;
  border: 0;
  border-radius: 6px;
  padding: 0 14px;
  cursor: pointer;
  text-decoration: none;
  white-space: nowrap;
}

.primary {
  flex: 1;
  background: var(--green);
  color: #fff;
  font-weight: 700;
  border: 1px solid transparent;
  box-shadow: none;
}

.primary:hover {
  background: var(--green-dark);
}

.ghost,
.link-button {
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink);
}

.icon {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  padding: 0;
  border: 1px solid var(--line);
  background: #fff;
  color: #66716d;
  font-size: 24px;
  font-weight: 600;
  line-height: 1;
}

.message-editor {
  display: grid;
  gap: 12px;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fbfdfc;
}

.editor-top {
  display: grid;
  grid-template-columns: 52px 1fr 34px;
  gap: 10px;
  align-items: start;
}

.avatar-picker {
  position: relative;
  width: 52px;
  height: 52px;
  cursor: pointer;
}

.avatar-picker img {
  width: 52px;
  height: 52px;
  border-radius: 6px;
  object-fit: cover;
}

.avatar-picker input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.editor-fields {
  display: grid;
  grid-template-columns: 1fr 92px;
  gap: 10px;
}

.preview-area {
  display: grid;
  align-content: start;
  gap: 18px;
}

.preview-toolbar {
  min-height: 52px;
  padding: 0 4px;
}

.preview-toolbar strong {
  display: block;
  font-size: 18px;
}

.preview-toolbar span {
  color: var(--muted);
  font-size: 13px;
}

.phone {
  width: min(100%, 640px);
  margin: 0 auto;
  padding: 18px;
  border: 1px solid rgba(23, 33, 29, 0.11);
  border-radius: 8px;
  background: #d9dcda;
  box-shadow: 0 30px 70px rgba(17, 24, 39, 0.16);
}

.preview-module {
  display: grid;
  gap: 10px;
}

.preview-module + .preview-module {
  margin-top: 16px;
}

.preview-module h2 {
  margin: 0;
  color: #59645f;
  font-size: 14px;
  line-height: 1.3;
  font-weight: 700;
}

.wx-forward {
  position: relative;
  display: grid;
  grid-template-columns: 68px 1fr;
  gap: 20px;
  align-items: start;
  max-width: 520px;
  margin-bottom: 18px;
}

.wx-forward::after {
  content: "";
  position: absolute;
  left: 83px;
  top: 22px;
  width: 18px;
  height: 18px;
  background: #fff;
  transform: rotate(45deg);
  border-radius: 2px;
}

.wx-forward > img {
  width: 68px;
  height: 68px;
  border-radius: 8px;
  object-fit: cover;
}

.forward-content {
  position: relative;
  z-index: 1;
  min-height: 152px;
  padding: 19px 20px 16px;
  border-radius: 5px;
  background: #fff;
}

.forward-title {
  margin-bottom: 7px;
  color: #1f1f1f;
  font-size: 23px;
  line-height: 1.25;
  word-break: break-word;
}

.forward-desc {
  color: #6b6b6b;
  font-size: 20px;
  line-height: 1.42;
  white-space: pre-line;
  display: -webkit-box;
  -webkit-line-clamp: 4;
  -webkit-box-orient: vertical;
  overflow: hidden;
  word-break: break-word;
}

.chat-page {
  min-height: 420px;
  padding: 22px;
  background: #fff;
  border-radius: 6px;
}

.chat-day {
  margin: 0 0 12px;
  color: #969696;
  text-align: center;
  font-size: 13px;
}

.chat-message {
  position: relative;
  display: grid;
  grid-template-columns: 62px 1fr;
  gap: 20px;
  min-height: 112px;
  margin: 0 0 18px;
}

.chat-message img {
  width: 62px;
  height: 62px;
  border-radius: 5px;
  object-fit: cover;
}

.chat-content {
  position: relative;
  min-width: 0;
  padding-bottom: 18px;
  border-bottom: 1px solid #ededed;
}

.chat-message:last-child .chat-content {
  border-bottom: 0;
}

.chat-message:last-child::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 1px;
  background: linear-gradient(
    to right,
    #ededed 0,
    #ededed calc(50% - 14px),
    transparent calc(50% - 14px),
    transparent calc(50% + 14px),
    #ededed calc(50% + 14px),
    #ededed 100%
  );
}

.chat-message:last-child::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: -2px;
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #e2e2e2;
  transform: translateX(-50%);
}

.chat-meta {
  min-height: 30px;
  padding-right: 72px;
}

.chat-name {
  color: #686868;
  font-size: 21px;
  line-height: 1.25;
}

.chat-time {
  position: absolute;
  top: 0;
  right: 0;
  color: #aaa;
  font-size: 20px;
  line-height: 1.25;
}

.chat-text {
  margin-top: 6px;
  color: #0b0b0b;
  font-size: 27px;
  line-height: 1.35;
  letter-spacing: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

.result,
.history {
  width: min(100%, 640px);
  margin: 0 auto;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.9);
}

.result {
  display: grid;
  gap: 12px;
}

.result-head {
  min-width: 0;
}

.result p {
  color: var(--muted);
  font-size: 13px;
}

.result-row input {
  flex: 1;
}

.history {
  display: grid;
  gap: 12px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
}

.history-item .link-button,
.result-head .link-button {
  display: inline-grid;
  place-items: center;
  min-width: 88px;
  padding: 0 16px;
}

.history-item .link-button {
  justify-self: end;
}

.history-title {
  overflow: hidden;
  font-weight: 600;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-desc {
  overflow: hidden;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.hidden {
  display: none !important;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .panel {
    max-height: none;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 12px;
  }

  .panel,
  .phone,
  .result,
  .history {
    border-radius: 6px;
  }

  .phone {
    padding: 10px;
  }

  .wx-forward {
    grid-template-columns: 52px 1fr;
    gap: 14px;
  }

  .wx-forward::after {
    left: 63px;
    top: 17px;
  }

  .wx-forward > img {
    width: 52px;
    height: 52px;
  }

  .forward-content {
    min-height: 122px;
    padding: 14px;
  }

  .forward-title {
    font-size: 19px;
  }

  .forward-desc {
    font-size: 16px;
  }

  .chat-page {
    padding: 16px;
  }

  .chat-message {
    grid-template-columns: 46px 1fr;
    gap: 14px;
    min-height: 86px;
    margin-bottom: 14px;
  }

  .chat-message img {
    width: 46px;
    height: 46px;
  }

  .chat-content {
    padding-bottom: 14px;
  }

  .chat-meta {
    min-height: 23px;
    padding-right: 56px;
  }

  .chat-name {
    font-size: 16px;
  }

  .chat-time {
    font-size: 15px;
  }

  .chat-text {
    font-size: 21px;
  }

  .editor-fields {
    grid-template-columns: 1fr;
  }
}

/* Admin layout refresh */
:root {
  --page: #f6f8f7;
  --panel: #ffffff;
  --text: #18221e;
  --muted: #7b8782;
  --line: #e3e9e6;
  --soft: #f7faf8;
  --green: #20c764;
  --green-dark: #119447;
}

body {
  background:
    radial-gradient(circle at 12% 0%, rgba(32, 199, 100, 0.1), transparent 30%),
    linear-gradient(180deg, #fbfdfc 0%, var(--page) 100%);
}

.app-shell {
  grid-template-columns: minmax(360px, 440px) minmax(520px, 1fr);
  gap: 28px;
  max-width: 1500px;
  margin: 0 auto;
  padding: 24px;
}

.panel {
  max-height: calc(100vh - 48px);
  padding: 24px;
  border-color: rgba(24, 34, 30, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 18px 45px rgba(24, 34, 30, 0.08);
}

.brand {
  margin-bottom: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--line);
}

.brand-mark {
  width: 48px;
  height: 48px;
  border-radius: 10px;
  box-shadow: 0 10px 24px rgba(32, 199, 100, 0.24);
}

.brand h1 {
  font-size: 21px;
  line-height: 1.2;
}

.brand p {
  font-size: 13px;
  line-height: 1.45;
}

.form,
.section {
  gap: 14px;
}

.section {
  padding-top: 0;
  border-top: 0;
}

.section + .section {
  padding-top: 20px;
  border-top: 1px solid var(--line);
}

.section h2,
.history h2,
.result h2 {
  color: #17211d;
  font-size: 16px;
  line-height: 1.3;
}

label {
  gap: 8px;
}

label span {
  color: #75817c;
  font-size: 13px;
  font-weight: 600;
}

input,
textarea {
  border-color: var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 15px;
}

input {
  height: 44px;
  padding: 0 14px;
}

textarea {
  min-height: 92px;
  padding: 12px 14px;
}

button,
.link-button {
  height: 44px;
  border-radius: 8px;
  font-weight: 700;
}

.primary {
  box-shadow: none;
}

.ghost,
.link-button {
  border-color: var(--line);
  background: #fff;
}

.actions {
  z-index: 3;
  margin-top: 2px;
  padding: 14px 0 0;
  border-top: 1px solid var(--line);
  background: transparent;
}

.message-editor {
  gap: 14px;
  margin-bottom: 14px;
  padding: 14px;
  border-color: var(--line);
  border-radius: 10px;
  background: var(--soft);
}

.editor-top {
  grid-template-columns: 54px 1fr 36px;
  gap: 12px;
}

.avatar-picker,
.avatar-picker img {
  width: 54px;
  height: 54px;
}

.avatar-picker img {
  border-radius: 8px;
  border: 1px solid rgba(24, 34, 30, 0.06);
}

.editor-fields {
  grid-template-columns: minmax(0, 1fr) 96px;
}

.icon {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  color: #8a9691;
}

.remove {
  align-self: start;
  border-color: #dfe7e3;
  background: #fff;
  color: #8b9691;
}

.remove:hover {
  border-color: #cfd9d4;
  background: #f6f8f7;
  color: #44504b;
}

.preview-area {
  gap: 18px;
  padding: 0 0 28px;
}

.preview-toolbar {
  position: sticky;
  top: 0;
  z-index: 2;
  min-height: 64px;
  padding: 10px 0;
  background: linear-gradient(#fbfdfc 70%, rgba(251, 253, 252, 0));
}

.preview-toolbar strong {
  font-size: 20px;
}

.preview-toolbar span {
  margin-top: 3px;
  display: block;
}

.phone {
  width: min(100%, 690px);
  padding: 18px;
  border-color: rgba(24, 34, 30, 0.12);
  border-radius: 12px;
  background: #d9dcda;
  box-shadow: 0 24px 55px rgba(24, 34, 30, 0.14);
}

.preview-module h2 {
  color: #4f5b56;
}

.result,
.history {
  width: min(100%, 690px);
  border-color: rgba(24, 34, 30, 0.08);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: 0 14px 34px rgba(24, 34, 30, 0.06);
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: minmax(320px, 400px) minmax(430px, 1fr);
    gap: 20px;
    padding: 18px;
  }

  .panel {
    padding: 20px;
  }
}

@media (max-width: 860px) {
  body {
    background: #f7faf8;
  }

  .app-shell {
    display: flex;
    flex-direction: column;
    gap: 18px;
    min-height: 0;
    padding: 14px;
  }

  .panel {
    order: 1;
    max-height: none;
    overflow: visible;
    padding: 18px;
    border-radius: 12px;
  }

  .preview-area {
    order: 2;
    padding-bottom: 18px;
  }

  .preview-toolbar {
    position: static;
    min-height: 0;
    padding: 4px 2px;
    background: transparent;
  }

  .preview-toolbar strong {
    font-size: 18px;
  }

  .actions {
    position: static;
    display: grid;
    grid-template-columns: 1fr 112px;
    padding-top: 16px;
    background: transparent;
  }

  .phone,
  .result,
  .history {
    width: 100%;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
  }

  .panel {
    padding: 16px;
  }

  .brand {
    gap: 12px;
    margin-bottom: 18px;
    padding-bottom: 18px;
  }

  .brand-mark {
    width: 44px;
    height: 44px;
    font-size: 22px;
  }

  .brand h1 {
    font-size: 19px;
  }

  .brand p {
    font-size: 12px;
  }

  .section + .section {
    padding-top: 18px;
  }

  .section-head {
    align-items: center;
  }

  input,
  textarea,
  button,
  .link-button {
    font-size: 15px;
  }

  input,
  button,
  .link-button {
    height: 46px;
  }

  textarea {
    min-height: 86px;
  }

  .editor-top {
    grid-template-columns: 50px 1fr 34px;
    gap: 10px;
  }

  .avatar-picker,
  .avatar-picker img {
    width: 50px;
    height: 50px;
  }

  .editor-fields {
    grid-template-columns: 1fr;
    gap: 8px;
  }

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

  .phone {
    padding: 8px;
    border-radius: 10px;
    box-shadow: 0 14px 34px rgba(24, 34, 30, 0.12);
  }

  .preview-module {
    gap: 8px;
  }

  .preview-module + .preview-module {
    margin-top: 12px;
  }

  .wx-forward {
    max-width: none;
    margin-bottom: 10px;
  }

  .result,
  .history {
    padding: 14px;
    border-radius: 10px;
  }

  .result-row,
  .history-item {
    grid-template-columns: 1fr;
  }

  .result-row {
    display: grid;
  }

  .history-item .link-button {
    display: grid;
    place-items: center;
    justify-self: stretch;
  }
}

/* Mobile overflow and chat scale fixes */
html,
body {
  max-width: 100%;
  overflow-x: hidden;
}

.app-shell,
.panel,
.preview-area,
.phone,
.preview-module,
.wx-forward,
.forward-content,
.chat-page,
.chat-content,
.chat-text,
.message-editor,
.editor-fields {
  min-width: 0;
}

.forward-title,
.forward-desc,
.chat-text,
textarea,
input {
  overflow-wrap: anywhere;
  word-break: break-all;
}

@media (max-width: 560px) {
  .app-shell {
    width: 100%;
    padding: 8px;
    overflow: hidden;
  }

  .panel,
  .preview-area,
  .phone,
  .result,
  .history {
    width: 100%;
    max-width: 100%;
  }

  .panel {
    padding: 14px;
  }

  .phone {
    margin: 0;
    padding: 8px;
  }

  .wx-forward {
    grid-template-columns: 44px minmax(0, 1fr);
    gap: 12px;
    max-width: 100%;
  }

  .wx-forward::after {
    left: 52px;
    top: 14px;
    width: 14px;
    height: 14px;
  }

  .wx-forward > img {
    width: 44px;
    height: 44px;
    border-radius: 6px;
  }

  .forward-content {
    min-height: 104px;
    padding: 12px;
  }

  .forward-title {
    margin-bottom: 5px;
    font-size: 17px;
    line-height: 1.22;
  }

  .forward-desc {
    font-size: 14px;
    line-height: 1.36;
  }

  .chat-page {
    padding: 12px;
    min-height: 0;
  }

  .chat-day {
    margin-bottom: 10px;
    font-size: 12px;
  }

  .chat-message {
    grid-template-columns: 40px minmax(0, 1fr);
    gap: 10px;
    min-height: 70px;
    margin-bottom: 12px;
  }

  .chat-message img {
    width: 40px;
    height: 40px;
    border-radius: 5px;
  }

  .chat-content {
    padding-bottom: 12px;
  }

  .chat-meta {
    min-height: 18px;
    padding-right: 46px;
  }

  .chat-name {
    font-size: 15px;
    line-height: 1.15;
  }

  .chat-time {
    font-size: 15px;
    line-height: 1.15;
  }

  .chat-text {
    margin-top: 2px;
    font-size: 18px;
    line-height: 1.28;
    max-width: 100%;
    overflow: hidden;
    word-break: break-all;
    overflow-wrap: anywhere;
  }

  .message-editor {
    overflow: hidden;
  }

  .history-list,
  .history-item,
  .history-item > div,
  .history-title,
  .history-desc {
    min-width: 0;
    max-width: 100%;
  }

  .history-item {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
  }

  .history-title,
  .history-desc {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-all;
  }

  .history-item .link-button {
    width: 100%;
  }
}
