:root {
  --page-bg: linear-gradient(180deg, #eefbf5 0%, #f7fbf8 100%);
  --shell-bg: #f7fbf8;
  --header-from: #2ec07c;
  --header-to: #0891b2;
  --header-fg: #ffffff;
  --header-sub-fg: rgba(255,255,255,0.84);
  --feed-bg: #eef5f2;
  --feed-overlay: rgba(68, 116, 98, 0.08);
  --system-chip-bg: rgba(255,255,255,0.96);
  --system-chip-border: rgba(54, 113, 91, 0.10);
  --operator-bg: #ffffff;
  --operator-fg: #1f382f;
  --visitor-bg: linear-gradient(180deg, #56d5a6 0%, #2b9c78 100%);
  --visitor-fg: #ffffff;
  --input-bg: #ffffff;
  --input-border: rgba(97, 182, 148, 0.34);
  --composer-bg: #f7fbf8;
  --tool-bg: #ffffff;
  --tool-fg: #5f766f;
  --send-from: #51daa0;
  --send-to: #149db8;
  --shadow: 0 18px 38px rgba(35, 116, 86, 0.12);
  --shell-radius: 0px;
  --bubble-radius: 18px;
  --header-height: 94px;
  --avatar-size: 58px;
  --send-width: 90px;
  --content-max: 430px;
  --tool-size: 54px;
  --composer-height: 88px;
  --canvas-chip-pad-x: 16px;
  --canvas-chip-pad-y: 11px;
  --canvas-line-height: 24px;
  --canvas-font-size: 18px;
  --meta-color: #5b6787;
  --panel-stroke: 2px;
  --input-shadow: 0 0 0 3px rgba(255,255,255,0.18);
  --feed-inset: 0 0 0 1px rgba(255,255,255,0.36);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  min-height: 100%;
  width: 100%;
  max-width: 100%;
  background: var(--page-bg);
}

body {
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  color: #162239;
  overflow: hidden;
  overflow-x: hidden;
}

.chat-shell {
  min-height: 100svh;
  height: 100svh;
  width: 100%;
  max-width: 100vw;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background: var(--shell-bg);
  border-radius: var(--shell-radius);
  overflow: hidden;
}

.shell-header {
  position: relative;
  display: flex;
  align-items: center;
  gap: 16px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-height: var(--header-height);
  padding: 20px 18px 18px;
  background: linear-gradient(135deg, var(--header-from) 0%, var(--header-to) 100%);
  color: var(--header-fg);
  overflow: hidden;
}

.shell-header::after {
  content: "";
  position: absolute;
  inset: auto 0 0;
  height: 1px;
  background: rgba(255, 255, 255, 0.14);
}

.header-avatar-skeleton,
.operator-avatar {
  width: var(--avatar-size);
  height: var(--avatar-size);
  border-radius: 999px;
  flex: 0 0 auto;
}

.header-avatar-skeleton {
  border: var(--panel-stroke) solid rgba(255, 255, 255, 0.7);
  background: rgba(255, 255, 255, 0.18);
}

.operator-avatar {
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  border: var(--panel-stroke) solid rgba(255, 255, 255, 0.75);
  background: rgba(255, 255, 255, 0.18);
}

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

.operator-avatar-fallback {
  width: 24px;
  height: 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.42);
}

.header-copy-skeleton,
.operator-copy {
  min-width: 0;
  flex: 1 1 auto;
}

.operator-name,
.operator-status {
  display: block;
  min-height: 16px;
}

.operator-name canvas,
.operator-status canvas,
.session-chip canvas,
.status-surface canvas,
.canvas-text canvas {
  display: block;
  max-width: 100%;
  height: auto !important;
}

.canvas-host,
.canvas-text {
  display: block;
  max-width: 100%;
  min-width: 0;
}

.skeleton-line {
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.26);
}

.skeleton-line-lg {
  width: 112px;
  height: 18px;
  margin-bottom: 10px;
}

.skeleton-line-sm {
  width: 64px;
  height: 12px;
}

.gesture-hint {
  position: absolute;
  inset: 50% auto auto 50%;
  width: 176px;
  height: 176px;
  transform: translate(-50%, -50%);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
  z-index: 3;
  opacity: 0.96;
  transition: opacity 220ms ease, transform 220ms ease;
}

.gesture-hint.hidden {
  opacity: 0;
  transform: translate(-50%, -46%);
}

.gesture-graphic {
  position: relative;
  width: 176px;
  height: 176px;
  display: block;
}

.gesture-ripple,
.gesture-spark,
.gesture-hand-mask {
  position: absolute;
  pointer-events: none;
}

.gesture-ripple {
  left: 50%;
  top: 50%;
  width: 18px;
  height: 18px;
  margin-left: -9px;
  margin-top: -9px;
  border-radius: 999px;
  border: 4px solid var(--gesture-ring-color);
  box-shadow: 0 0 0 8px var(--gesture-glow-color);
  opacity: 0;
  animation: gesturePulse 1.75s ease-out infinite;
}

.gesture-ripple.ripple-b {
  animation-delay: 0.18s;
}

.gesture-ripple.ripple-c {
  animation-delay: 0.36s;
}

.gesture-spark {
  left: 50%;
  top: 50%;
  width: 5px;
  height: 20px;
  margin-left: -2.5px;
  margin-top: -50px;
  border-radius: 999px;
  background: var(--gesture-ring-color);
  box-shadow: 0 0 14px var(--gesture-glow-color);
  opacity: 0.82;
  transform-origin: 50% 58px;
  animation: gestureSpark 1.75s ease-in-out infinite;
}

.gesture-spark.spark-b { transform: rotate(40deg); }
.gesture-spark.spark-c { transform: rotate(80deg); }
.gesture-spark.spark-d { transform: rotate(120deg); }
.gesture-spark.spark-e { transform: rotate(160deg); }

.gesture-graphic[data-animation="ring"] .gesture-spark,
.gesture-graphic[data-animation="double-ring"] .gesture-spark {
  display: none;
}

.gesture-graphic[data-animation="spark"] .gesture-ripple.ripple-c {
  display: none;
}

.gesture-hand-mask {
  width: var(--gesture-hand-width);
  height: var(--gesture-hand-height);
  left: calc(50% - var(--gesture-tip-left));
  top: calc(50% - var(--gesture-tip-top));
  background: var(--gesture-hand-color);
  -webkit-mask-image: var(--gesture-mask);
  mask-image: var(--gesture-mask);
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-size: 100% 100%;
  mask-size: 100% 100%;
  filter: drop-shadow(0 8px 20px var(--gesture-glow-color));
  animation: gestureTap 1.75s ease-in-out infinite;
}

@keyframes gesturePulse {
  0% {
    opacity: 0;
    transform: scale(0.74);
  }
  28% {
    opacity: 0.84;
  }
  100% {
    opacity: 0;
    transform: scale(1.18);
  }
}

@keyframes gestureSpark {
  0%, 100% {
    opacity: 0.2;
    transform: scaleY(0.72);
  }
  34% {
    opacity: 0.9;
    transform: scaleY(1);
  }
}

@keyframes gestureTap {
  0%, 100% {
    transform: translate(0, 0);
  }
  34% {
    transform: translate(1px, 7px);
  }
  62% {
    transform: translate(0, 0);
  }
}

.chat-feed {
  position: relative;
  min-height: 0;
  width: 100%;
  max-width: 100%;
  overflow-y: auto;
  overflow-x: hidden;
  padding: 16px 0 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24) 0%, rgba(255, 255, 255, 0) 12%),
    var(--feed-bg);
  box-shadow: inset var(--feed-inset);
}

.status-surface,
.session-chip {
  display: flex;
  justify-content: center;
  padding: 4px 18px 10px;
}

.status-inner,
.session-chip-inner {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 var(--canvas-chip-pad-x);
  border-radius: 999px;
  border: 1px solid var(--system-chip-border);
  background: var(--system-chip-bg);
  box-shadow: 0 10px 20px rgba(64, 86, 136, 0.06);
}

.status-inner {
  gap: 10px;
}

.retry-button {
  min-width: 84px;
  height: 36px;
  padding: 0 16px;
  border-radius: 999px;
  border: 1px solid rgba(131, 158, 255, 0.34);
  background: #ffffff;
  color: #5c67dd;
  font-size: 15px;
  font-weight: 600;
}

.message-list {
  display: none;
  flex-direction: column;
  gap: 12px;
  padding:
    8px
    calc(14px + env(safe-area-inset-right))
    20px
    calc(14px + env(safe-area-inset-left));
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  overflow-x: hidden;
  align-items: stretch;
}

.message-list.ready {
  display: flex;
}

.message-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 6px;
  width: 100%;
  min-width: 0;
  box-sizing: border-box;
  justify-items: start;
}

.message-row.visitor {
  justify-items: end;
  padding-left: calc(52px + env(safe-area-inset-left));
  padding-right: calc(12px + env(safe-area-inset-right));
}

.message-row.admin {
  justify-items: start;
  padding-left: calc(12px + env(safe-area-inset-left));
  padding-right: calc(52px + env(safe-area-inset-right));
}

.message-row.visitor .message-meta {
  text-align: right;
  justify-self: end;
}

.message-row.admin .message-meta {
  text-align: left;
  justify-self: start;
}

.message-meta {
  display: inline-block;
  width: fit-content;
  font-size: 12px;
  line-height: 1.4;
  color: var(--meta-color);
  max-width: min(100%, calc(100vw - 98px), var(--content-max));
  box-sizing: border-box;
  overflow-wrap: anywhere;
}

.message-bubble {
  display: inline-flex;
  flex-direction: column;
  width: auto;
  min-width: 0;
  max-width: min(100%, calc(100vw - 122px), var(--content-max));
  padding: 12px 14px;
  border-radius: var(--bubble-radius);
  box-shadow: 0 10px 24px rgba(51, 74, 128, 0.08);
  box-sizing: border-box;
  overflow: hidden;
}

.message-row.admin .message-bubble {
  background: var(--operator-bg);
  color: var(--operator-fg);
  justify-self: start;
}

.message-row.visitor .message-bubble {
  background: var(--visitor-bg);
  color: var(--visitor-fg);
  justify-self: end;
}

.message-body-text {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  font-size: 17px;
  line-height: 1.58;
}

.message-image {
  display: block;
  max-width: min(72vw, 280px);
  border-radius: 16px;
  margin-top: 8px;
}

.typing-bubble {
  min-width: 124px;
}

.typing-bubble canvas {
  opacity: 0.84;
  animation: pulseCanvas 1.2s ease-in-out infinite;
}

@keyframes pulseCanvas {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

.skeleton-feed {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 10px 18px 20px;
}

.skeleton-card {
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.66);
  box-shadow: 0 10px 24px rgba(52, 82, 143, 0.05);
}

.skeleton-card-center {
  width: 220px;
  height: 46px;
  align-self: center;
}

.skeleton-card-left {
  width: min(72vw, 280px);
  height: 80px;
}

.skeleton-card-right {
  width: 78px;
  height: 66px;
  align-self: flex-end;
}

.composer {
  position: relative;
  display: grid;
  grid-template-columns: var(--tool-size) minmax(0, 1fr) minmax(72px, var(--send-width));
  align-items: center;
  gap: 12px;
  width: 100%;
  max-width: 100%;
  box-sizing: border-box;
  min-height: var(--composer-height);
  padding: 14px 12px calc(14px + env(safe-area-inset-bottom)) 12px;
  background: var(--composer-bg);
  border-top: 1px solid rgba(122, 146, 196, 0.12);
  overflow: hidden;
}

.composer-disabled {
  opacity: 0.98;
}

.hidden-upload,
.hidden {
  display: none !important;
}

.tool-button {
  width: var(--tool-size);
  height: var(--tool-size);
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 999px;
  border: 1px solid rgba(140, 167, 233, 0.34);
  background: var(--tool-bg);
  color: var(--tool-fg);
  box-shadow: 0 10px 22px rgba(69, 93, 146, 0.08);
}

.tool-button svg {
  width: 24px;
  height: 24px;
  display: block;
}

.message-input {
  min-width: 0;
  width: 100%;
  height: 54px;
  padding: 0 18px;
  border-radius: 999px;
  border: 1px solid var(--input-border);
  background: var(--input-bg);
  box-shadow: var(--input-shadow);
  outline: none;
  color: #203149;
  font-size: 16px;
}

.message-input::placeholder {
  color: #95a3be;
}

.send-button {
  width: 100%;
  height: 54px;
  min-width: 72px;
  max-width: var(--send-width);
  justify-self: stretch;
  border: 0;
  border-radius: 999px;
  background: linear-gradient(180deg, var(--send-from) 0%, var(--send-to) 100%);
  color: #ffffff;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 14px 28px rgba(76, 101, 214, 0.22);
}

.attachment-note {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: calc(100% + 8px);
  min-height: 34px;
  padding: 8px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(136, 160, 212, 0.22);
  color: #5871a7;
  font-size: 13px;
  line-height: 1.4;
  box-shadow: 0 8px 18px rgba(70, 93, 144, 0.08);
}

@media (min-width: 720px) {
  .chat-shell {
    max-width: 560px;
    margin: 0 auto;
    box-shadow: var(--shadow);
  }
}
