:root {
  --teal: #1a7a72;
  --teal-deep: #0f4f4a;
  --ink: #173038;
  --muted: #5b6f76;
  --glass: #f4faf8;
  --line: rgba(255, 255, 255, 0.62);
  --shadow: 0 16px 40px rgba(16, 36, 40, 0.18);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #eef4f3;
  color: var(--ink);
}

.chrome {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  height: 56px;
  padding: 0 16px;
  border-bottom: 1px solid #d7e4e1;
  background: #f7fbfa;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.brand img {
  width: 36px;
  height: 36px;
}

.brand strong,
.panel-head strong {
  display: block;
  font-size: 13px;
}

.brand span,
.panel-head span,
.disclaimer {
  color: var(--muted);
  font-size: 11px;
}

.chrome-meta {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pill {
  padding: 4px 8px;
  border-radius: 999px;
  background: #e1f4e8;
  color: #1d6b45;
  font-size: 11px;
}

.pill.warn {
  background: #fff3d8;
  color: #8a5a12;
}

.chrome a {
  color: var(--teal);
  font-size: 12px;
}

.chrome[hidden] {
  display: none;
}

/* 默认整屏就是店铺页，调试壳藏起来；body.dev 时才让出顶部 56px。 */
.store {
  height: 100%;
}

body.dev .store {
  height: calc(100% - 56px);
}

.store iframe {
  width: 100%;
  height: 100%;
  border: 0;
  background: #fff;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  pointer-events: none;
}

body.dev .overlay {
  inset: 56px 0 0;
}

/* 定位原点是爪爪自己：窗口只占它那 240，面板挂在旁边绝对定位。
   这样拖到哪儿开聊天，爪爪都不会被面板顶走。 */
.widget {
  position: absolute;
  right: 18px;
  bottom: 10px;
  width: 240px;
  pointer-events: none;
}

.panel,
.stage,
.controls,
.mic,
.chat-toggle,
.icon-btn,
.send,
.chips button {
  pointer-events: auto;
}

.panel {
  position: absolute;
  right: calc(100% + 10px);
  bottom: 0;
  width: 340px;
  max-width: min(340px, calc(100vw - 24px));
  height: auto;
  max-height: min(72vh, 560px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  isolation: isolate;
  border: 1px solid #d7e4e1;
  border-radius: 18px;
  background: var(--glass);
  box-shadow: var(--shadow);
}

.panel[hidden] {
  display: none;
}

/* 左边挤不下就翻到右边，由 placePanel() 决定。 */
.widget.panel-right .panel {
  right: auto;
  left: calc(100% + 10px);
}

.panel-head {
  display: grid;
  grid-template-columns: 42px 1fr 28px;
  gap: 8px;
  align-items: center;
  padding: 10px 10px 0;
}

.panel-head img {
  width: 42px;
  height: 42px;
  object-fit: contain;
}

.icon-btn,
.send,
.mic,
.chat-toggle,
.chips button {
  appearance: none;
  border: 1px solid rgba(26, 122, 114, 0.28);
  background: #fff;
  color: var(--teal-deep);
  cursor: pointer;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  font-size: 16px;
}

.panel-head,
.disclaimer,
.chips,
.composer {
  flex-shrink: 0;
}

.disclaimer {
  margin: 8px 12px 0;
  line-height: 1.4;
}

.log {
  flex: 0 1 auto;
  min-width: 0;
  min-height: 0;
  max-height: min(42vh, 320px);
  margin: 8px 0 0;
  padding: 0 12px 8px;
  overflow-x: hidden;
  overflow-y: auto;
}

.msg {
  width: fit-content;
  max-width: 100%;
  margin: 8px 0;
  padding: 8px 10px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.45;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.msg.user {
  margin-left: auto;
  background: var(--teal);
  color: #fff;
}

.msg.user.pending {
  opacity: 0.72;
}

.msg.agent {
  background: #fff;
  border: 1px solid #d7e4e1;
}

.cards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 4px 12px 8px;
  pointer-events: auto;
}

.pick {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 8px;
  padding: 8px;
  border: 1px solid #d7e4e1;
  border-radius: 12px;
  background: #fff;
}

.pick img {
  width: 72px;
  height: 72px;
  object-fit: contain;
  background: #f4faf8;
  border-radius: 8px;
  cursor: zoom-in;
}

.pick strong,
.pick p {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 4;
  overflow: hidden;
}

.pick strong {
  font-size: 13px;
}

.pick p {
  margin: 4px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.pick-grade {
  display: block;
  margin-bottom: 2px;
  font-size: 10px;
  font-style: normal;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--teal);
}

.pick-alt .pick-grade,
.pick-fallback .pick-grade {
  color: #8a6a2b;
}

.pick-value .pick-grade {
  color: #2f6f4e;
}

.pick-alt,
.pick-fallback {
  background: #fffdf6;
}

.pick-value {
  background: #f4faf6;
}

.pick-open {
  grid-column: 2;
  justify-self: start;
  appearance: none;
  padding: 6px 12px;
  border: 0;
  border-radius: 999px;
  background: var(--teal);
  color: #fff;
  font-size: 12px;
  cursor: pointer;
}

.lightbox {
  position: fixed;
  inset: 0;
  z-index: 80;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(16, 36, 40, 0.72);
  pointer-events: auto;
}

.lightbox[hidden] {
  display: none;
}

.lightbox img {
  max-width: min(92vw, 720px);
  max-height: 86vh;
  object-fit: contain;
  background: #fff;
  border-radius: 12px;
}

.lightbox-close {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 36px;
  height: 36px;
  border: 0;
  border-radius: 999px;
  background: #fff;
  color: #173038;
  font-size: 22px;
  cursor: pointer;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-width: 0;
  padding: 0 12px 8px;
}

.chips button {
  max-width: 100%;
  padding: 5px 8px;
  border-radius: 999px;
  font-size: 11px;
  white-space: normal;
  text-align: left;
  overflow-wrap: anywhere;
}

.composer {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  padding: 0 12px 12px;
}

.composer input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid #d3e2df;
  border-radius: 12px;
  font: 13px/1.4 inherit;
}

.send {
  padding: 0 12px;
  border-radius: 12px;
  background: var(--teal);
  color: #fff;
}

.stage {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 240px;
}

.bubble {
  width: 220px;
  margin-bottom: 6px;
  padding: 10px 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #f4faf8;
  box-shadow: var(--shadow);
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  pointer-events: auto;
}

.bubble[hidden] {
  display: none;
}

.bubble p {
  margin: 0;
  max-height: calc(1.45em * 8);
  overflow-x: hidden;
  overflow-y: auto;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.bubble.listening p::after,
.bubble.thinking p::after {
  content: "▍";
  animation: caret 1s step-end infinite;
}

.pet-wrap {
  position: relative;
  width: 240px;
  height: 240px;
  cursor: grab;
  pointer-events: auto;
  touch-action: none;
}

.pet-wrap:active {
  cursor: grabbing;
}

.pet {
  position: absolute;
  inset: 0;
  display: block;
  width: 240px;
  height: 240px;
  object-fit: contain;
  user-select: none;
  -webkit-user-drag: none;
  image-rendering: auto;
  opacity: 0;
  pointer-events: none;
}

.pet.on {
  opacity: 1;
}

.listen-ring {
  position: absolute;
  inset: 18px;
  border: 3px solid rgba(26, 122, 114, 0.55);
  border-radius: 50%;
  animation: pulse 1.1s ease-out infinite;
  pointer-events: none;
}

.listen-ring[hidden] {
  display: none;
}

.controls {
  display: flex;
  gap: 6px;
  margin-top: -8px;
}

.mic,
.chat-toggle {
  padding: 7px 10px;
  border-radius: 999px;
  font-size: 12px;
  box-shadow: var(--shadow);
}

.mic.hot {
  background: var(--teal);
  color: #fff;
}

@keyframes caret {
  50% {
    opacity: 0;
  }
}

@keyframes pulse {
  from {
    transform: scale(0.92);
    opacity: 0.9;
  }
  to {
    transform: scale(1.08);
    opacity: 0;
  }
}

@media (max-width: 820px) {
  .widget {
    right: 8px;
  }

  .panel {
    width: min(340px, calc(100vw - 260px));
  }
}
