:root {
  color-scheme: light;
  --bg: #f4f0e4;
  --panel: rgba(255, 255, 255, 0.88);
  --ink: #16231f;
  --muted: #69766f;
  --line: rgba(8, 54, 43, 0.15);
  --teal: #0f5a47;
  --teal-dark: #073f32;
  --mint: #edf3ec;
  --gold: #c59a4a;
  --gold-soft: #e7d49a;
  --paper: #fbf8ef;
  font-family: "Microsoft YaHei", "PingFang SC", Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

body {
  margin: 0;
  background:
    linear-gradient(rgba(7, 63, 50, 0.055) 1px, transparent 1px),
    linear-gradient(90deg, rgba(7, 63, 50, 0.055) 1px, transparent 1px),
    linear-gradient(135deg, #f8f1df 0%, #eef1ea 48%, #d9e1d4 100%);
  background-size: 34px 34px, 34px 34px, auto;
  color: var(--ink);
}

body.viewer-open {
  overflow: hidden;
  overscroll-behavior: none;
}

body.dialog-open {
  overflow: hidden;
}

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

button,
a {
  -webkit-tap-highlight-color: transparent;
}

.app-shell {
  width: 100%;
  min-height: 100vh;
  margin: 0 auto;
  background: transparent;
}

.chat-panel {
  height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.88), rgba(251, 248, 239, 0.9)),
    var(--paper);
}

.chat-header {
  position: sticky;
  top: 0;
  z-index: 10;
  display: grid;
  grid-template-columns: 56px 1fr auto;
  gap: 10px;
  align-items: center;
  padding: 15px 14px 13px;
  border-bottom: 1px solid rgba(197, 154, 74, 0.38);
  background:
    radial-gradient(circle at 18% 0%, rgba(231, 212, 154, 0.44), transparent 34%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.94), rgba(245, 239, 222, 0.9));
  backdrop-filter: blur(16px);
  box-shadow: 0 12px 30px rgba(20, 44, 36, 0.08);
  overflow: hidden;
}

.chat-header::after {
  content: "";
  position: absolute;
  right: -58px;
  top: -74px;
  width: 170px;
  height: 170px;
  border: 1px solid rgba(197, 154, 74, 0.28);
  border-radius: 50%;
  box-shadow: inset 0 0 0 22px rgba(197, 154, 74, 0.06);
  pointer-events: none;
}

.pet-avatar {
  position: relative;
  z-index: 1;
  width: 52px;
  height: 52px;
  display: grid;
  place-items: center;
  animation: petFloat 3.8s ease-in-out infinite;
}

.pet-avatar img {
  position: relative;
  z-index: 2;
  width: 50px;
  height: 50px;
  object-fit: cover;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.96);
  box-shadow:
    0 0 0 4px rgba(231, 212, 154, 0.32),
    0 12px 28px rgba(7, 63, 50, 0.22);
}

.pet-glow {
  position: absolute;
  inset: 1px;
  border-radius: 50%;
  background: rgba(197, 154, 74, 0.28);
  filter: blur(12px);
  animation: petGlow 2.4s ease-in-out infinite;
}

.pet-avatar.is-speaking img,
.mini-pet.is-speaking {
  animation: petTalk 0.42s ease-in-out infinite;
}

.chat-title p {
  position: relative;
  z-index: 1;
  margin: 0 0 2px;
  color: var(--teal);
  font-size: 13px;
  font-weight: 700;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  position: relative;
  z-index: 1;
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
  color: var(--teal-dark);
}

.header-action {
  position: relative;
  z-index: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 54px;
  min-height: 36px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--teal-dark);
  background: var(--teal-dark);
  color: #fff;
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  box-shadow: 0 10px 20px rgba(7, 63, 50, 0.16);
}

.quick-list {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  overflow-x: auto;
  border-bottom: 1px solid rgba(197, 154, 74, 0.26);
  background: rgba(251, 248, 239, 0.72);
  scrollbar-width: none;
}

.quick-list::-webkit-scrollbar {
  display: none;
}

.quick-list button {
  flex: 0 0 auto;
  min-height: 38px;
  padding: 0 13px;
  border: 1px solid rgba(197, 154, 74, 0.36);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  box-shadow: 0 8px 18px rgba(20, 44, 36, 0.04);
}

.quick-list button:active {
  border-color: var(--gold);
  background: rgba(231, 212, 154, 0.22);
  color: var(--teal-dark);
}

.messages {
  min-height: 0;
  height: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 14px 12px 18px;
  overflow-y: auto;
  overscroll-behavior-y: auto;
  scroll-behavior: smooth;
  background:
    linear-gradient(180deg, rgba(251, 248, 239, 0.78), rgba(238, 241, 234, 0.9));
}

.message-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

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

.mini-pet {
  flex: 0 0 auto;
  width: 32px;
  height: 32px;
  display: block;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid rgba(255, 255, 255, 0.95);
  box-shadow:
    0 0 0 3px rgba(231, 212, 154, 0.34),
    0 8px 20px rgba(7, 63, 50, 0.14);
}

.message {
  max-width: 78%;
  padding: 11px 12px;
  border-radius: 8px;
  font-size: 15px;
  line-height: 1.65;
  white-space: pre-wrap;
}

.message.bot {
  border: 1px solid rgba(197, 154, 74, 0.28);
  background: rgba(255, 255, 255, 0.84);
  box-shadow: 0 12px 24px rgba(20, 44, 36, 0.06);
}

.message.user {
  background: linear-gradient(135deg, var(--teal-dark), var(--teal));
  color: #fff;
  box-shadow: 0 12px 24px rgba(7, 63, 50, 0.16);
}

.message.loading {
  color: var(--muted);
}

.message a {
  color: var(--teal-dark);
  font-weight: 700;
  text-decoration: underline;
  text-underline-offset: 3px;
  overflow-wrap: anywhere;
}

.message.user a {
  color: #fff;
}

.map-card-list {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.map-card {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 10px;
  min-height: 92px;
  padding: 8px;
  border: 1px solid rgba(7, 63, 50, 0.16);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-decoration: none;
  box-shadow: 0 12px 24px rgba(20, 44, 36, 0.08);
  overflow: hidden;
}

.map-preview {
  position: relative;
  min-height: 76px;
  border-radius: 7px;
  background:
    linear-gradient(rgba(7, 63, 50, 0.12) 1px, transparent 1px),
    linear-gradient(90deg, rgba(7, 63, 50, 0.12) 1px, transparent 1px),
    linear-gradient(135deg, #eef4e8, #d7e3d0);
  background-size: 18px 18px, 18px 18px, auto;
  border: 1px solid rgba(7, 63, 50, 0.1);
}

.map-preview::before,
.map-preview::after {
  content: "";
  position: absolute;
  background: rgba(197, 154, 74, 0.48);
  border-radius: 999px;
}

.map-preview::before {
  width: 70px;
  height: 7px;
  left: 8px;
  top: 20px;
  transform: rotate(-18deg);
}

.map-preview::after {
  width: 66px;
  height: 7px;
  left: 14px;
  bottom: 18px;
  transform: rotate(22deg);
}

.map-pin {
  position: absolute;
  left: 50%;
  top: 43%;
  z-index: 2;
  width: 22px;
  height: 22px;
  border-radius: 50% 50% 50% 0;
  background: var(--teal-dark);
  transform: translate(-50%, -50%) rotate(-45deg);
  box-shadow: 0 8px 16px rgba(7, 63, 50, 0.28);
}

.map-pin::after {
  content: "";
  position: absolute;
  left: 6px;
  top: 6px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #fff;
}

.map-body {
  min-width: 0;
  display: grid;
  align-content: center;
  gap: 4px;
}

.map-body strong {
  color: var(--teal-dark);
  font-size: 14px;
  line-height: 1.35;
}

.map-body span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.45;
}

.map-body em {
  justify-self: start;
  margin-top: 3px;
  padding: 5px 9px;
  border-radius: 999px;
  background: var(--teal-dark);
  color: #fff;
  font-size: 12px;
  font-style: normal;
  font-weight: 700;
}

.floorplan-gallery {
  display: grid;
  gap: 10px;
  margin-top: 12px;
}

.message > .floorplan-gallery:first-child {
  margin-top: 0;
  margin-bottom: 12px;
}

.message-text {
  white-space: pre-wrap;
}

.floorplan-card {
  display: grid;
  gap: 7px;
  padding: 8px;
  border: 1px solid rgba(197, 154, 74, 0.38);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.82);
  color: var(--ink);
  text-decoration: none;
}

.floorplan-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  object-position: center top;
  border-radius: 6px;
  background: #fff;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: none;
  grid-template-rows: 1fr auto;
  gap: 12px;
  padding: max(58px, calc(env(safe-area-inset-top) + 52px)) 12px max(16px, env(safe-area-inset-bottom));
  background: rgba(8, 23, 19, 0.92);
  backdrop-filter: blur(10px);
  overflow: hidden;
  overscroll-behavior: contain;
  touch-action: none;
  user-select: none;
}

.image-viewer.is-open {
  display: grid;
}

.image-viewer img {
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.04);
  transform-origin: center center;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
  will-change: transform;
}

.image-viewer-close {
  position: fixed;
  right: max(10px, env(safe-area-inset-right));
  top: max(10px, env(safe-area-inset-top));
  z-index: 1001;
  width: 42px;
  height: 42px;
  min-width: 42px;
  min-height: 42px;
  border: 1px solid rgba(231, 212, 154, 0.4);
  border-radius: 50%;
  padding: 0;
  background: rgba(7, 63, 50, 0.86);
  color: #fff;
  cursor: pointer;
  display: grid;
  place-items: center;
  font-size: 30px;
  line-height: 1;
  font-weight: 400;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.28);
  backdrop-filter: blur(8px);
  transform: none;
  transform-origin: center;
  flex: 0 0 auto;
  touch-action: manipulation;
  user-select: none;
}

.image-viewer-caption {
  color: rgba(255, 255, 255, 0.88);
  text-align: center;
  font-size: 14px;
  line-height: 1.5;
}

.floorplan-card strong {
  font-size: 14px;
  line-height: 1.35;
}

.floorplan-card span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.chat-input {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: 1fr 68px;
  gap: 8px;
  padding: 10px 10px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(197, 154, 74, 0.32);
  background: rgba(251, 248, 239, 0.92);
  backdrop-filter: blur(12px);
}

.chat-input input,
.lead-panel input,
.lead-panel textarea {
  width: 100%;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
  color: var(--ink);
  background: rgba(255, 255, 255, 0.86);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease, background 0.18s ease;
}

.chat-input input:focus,
.lead-panel input:focus,
.lead-panel textarea:focus {
  border-color: rgba(197, 154, 74, 0.78);
  background: #fff;
  box-shadow: 0 0 0 3px rgba(197, 154, 74, 0.16);
}

.chat-input button,
.lead-panel button {
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--teal-dark);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 14px 26px rgba(7, 63, 50, 0.2);
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}

.chat-input button:active,
.lead-panel button:active {
  transform: translateY(1px);
  box-shadow: 0 8px 18px rgba(7, 63, 50, 0.18);
}

.lead-panel {
  position: relative;
  margin: 14px 12px 16px;
  padding: 20px 18px 18px;
  border: 1px solid rgba(197, 154, 74, 0.52);
  border-radius: 8px;
  background:
    radial-gradient(circle at 88% 4%, rgba(197, 154, 74, 0.2), transparent 32%),
    linear-gradient(145deg, rgba(255, 255, 255, 0.94), rgba(251, 248, 239, 0.88));
  scroll-margin-top: 16px;
  box-shadow: 0 22px 48px rgba(20, 44, 36, 0.12);
  overflow: hidden;
}

.lead-panel::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 4px;
  background: linear-gradient(90deg, var(--gold), var(--teal-dark));
}

.lead-panel h2 {
  margin-bottom: 15px;
  font-size: 22px;
  color: var(--teal-dark);
  letter-spacing: 0;
}

.lead-panel form {
  display: grid;
  gap: 12px;
}

.lead-panel label {
  display: grid;
  gap: 7px;
  color: var(--teal-dark);
  font-size: 14px;
  font-weight: 700;
}

.form-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.success-dialog {
  position: fixed;
  inset: 0;
  z-index: 1200;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(8, 23, 19, 0.42);
  backdrop-filter: blur(10px);
}

.success-dialog.is-open {
  display: grid;
}

.success-dialog-panel {
  width: min(100%, 320px);
  padding: 24px 20px 20px;
  border: 1px solid rgba(197, 154, 74, 0.45);
  border-radius: 8px;
  background:
    radial-gradient(circle at 84% 0%, rgba(231, 212, 154, 0.34), transparent 34%),
    linear-gradient(145deg, #fff, #fbf8ef);
  color: var(--ink);
  text-align: center;
  box-shadow: 0 26px 70px rgba(8, 23, 19, 0.28);
}

.success-dialog-badge {
  width: 54px;
  height: 54px;
  margin: 0 auto 12px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--teal-dark);
  color: #fff;
  font-size: 30px;
  font-weight: 700;
  box-shadow: 0 12px 26px rgba(7, 63, 50, 0.22);
}

.success-dialog h2 {
  margin: 0 0 8px;
  color: var(--teal-dark);
  font-size: 22px;
  line-height: 1.25;
}

.success-dialog p {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.7;
}

.success-dialog button {
  width: 100%;
  min-height: 44px;
  border: 0;
  border-radius: 8px;
  background: var(--teal-dark);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 0 12px 24px rgba(7, 63, 50, 0.18);
}

@keyframes petFloat {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-4px);
  }
}

@keyframes petGlow {
  0%,
  100% {
    opacity: 0.45;
    transform: scale(0.92);
  }
  50% {
    opacity: 0.9;
    transform: scale(1.08);
  }
}

@keyframes petTalk {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

@media (min-width: 720px) {
  body {
    padding: 22px 0;
  }

  .app-shell {
    max-width: 460px;
    min-height: calc(100vh - 44px);
    border: 1px solid var(--line);
    border-radius: 18px;
    overflow: hidden;
    box-shadow: 0 24px 80px rgba(20, 44, 36, 0.18);
  }

  .chat-panel {
    height: 760px;
  }
}

.admin-shell {
  width: min(100%, 980px);
  margin: 0 auto;
  padding: 14px;
}

.admin-header,
.admin-login,
.lead-table-wrap {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.admin-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding: 16px;
  margin-bottom: 12px;
}

.admin-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.admin-header p {
  margin: 0 0 4px;
  color: var(--teal);
  font-weight: 700;
}

.admin-header h1 {
  font-size: 24px;
}

.admin-header button,
.admin-login button {
  min-height: 42px;
  border: 0;
  border-radius: 8px;
  padding: 0 16px;
  background: var(--teal-dark);
  color: #fff;
  cursor: pointer;
  font-weight: 700;
}

.admin-login {
  display: grid;
  gap: 12px;
  padding: 16px;
  margin-bottom: 12px;
}

.admin-login label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 14px;
}

.admin-login input {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 11px 12px;
}

.admin-login p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.lead-table-wrap {
  overflow-x: auto;
}

.lead-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 680px;
}

.lead-table th,
.lead-table td {
  padding: 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  font-size: 14px;
  line-height: 1.55;
}

.lead-table th {
  background: #fbfdfd;
  color: var(--teal-dark);
}

.lead-table a {
  color: var(--teal-dark);
  font-weight: 700;
}

.lead-table .delete-lead {
  min-height: 34px;
  border: 1px solid #efb4a8;
  border-radius: 8px;
  padding: 0 12px;
  background: #fff4f1;
  color: #9d2f20;
  cursor: pointer;
  font-weight: 700;
}

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

  .admin-header {
    display: grid;
    gap: 12px;
    padding: 14px;
  }

  .admin-header h1 {
    font-size: 22px;
    line-height: 1.25;
  }

  .admin-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
  }

  .admin-header button,
  .admin-login button {
    width: 100%;
    min-height: 44px;
  }

  .admin-login {
    padding: 14px;
  }

  .lead-table-wrap {
    border: 0;
    background: transparent;
    overflow: visible;
  }

  .lead-table {
    min-width: 0;
    border-collapse: separate;
    border-spacing: 0 10px;
  }

  .lead-table thead {
    display: none;
  }

  .lead-table,
  .lead-table tbody,
  .lead-table tr,
  .lead-table td {
    display: block;
    width: 100%;
  }

  .lead-table tr {
    padding: 12px;
    border: 1px solid rgba(7, 63, 50, 0.14);
    border-radius: 8px;
    background:
      radial-gradient(circle at 90% 0%, rgba(231, 212, 154, 0.22), transparent 30%),
      rgba(255, 255, 255, 0.9);
    box-shadow: 0 14px 30px rgba(20, 44, 36, 0.08);
  }

  .lead-table td {
    display: grid;
    grid-template-columns: 58px 1fr;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px solid rgba(8, 54, 43, 0.1);
    font-size: 14px;
    line-height: 1.6;
    overflow-wrap: anywhere;
  }

  .lead-table td:last-child {
    border-bottom: 0;
    padding-bottom: 0;
  }

  .lead-table td::before {
    content: attr(data-label);
    color: var(--muted);
    font-weight: 700;
  }

  .lead-table td[colspan] {
    display: block;
    padding: 16px;
    text-align: center;
    color: var(--muted);
  }

  .lead-table td[colspan]::before {
    content: "";
  }

  .lead-table .delete-lead {
    width: 100%;
    min-height: 40px;
  }
}

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