/* 卓越广告 · 悬浮 AI 客服小卓 */
.zw-root {
  --zw-primary: #e53935;
  --zw-primary-dark: #c62828;
  --zw-header-bg: linear-gradient(135deg, #e53935 0%, #ef5350 100%);
  --zw-user-bg: #ffebee;
  --zw-font: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  position: fixed;
  z-index: 99999;
  font-family: var(--zw-font);
  -webkit-font-smoothing: antialiased;
}

.zw-root[data-brand="zhuoyue"] {
  --zw-primary: #165dff;
  --zw-primary-dark: #0e4ad6;
  --zw-header-bg: linear-gradient(135deg, #165dff 0%, #f5a623 100%);
  --zw-user-bg: #e8f4ff;
}

.zw-root *,
.zw-root *::before,
.zw-root *::after {
  box-sizing: border-box;
}

/* 悬浮气泡 */
.zw-fab {
  position: fixed;
  right: 24px;
  bottom: 80px;
  width: 56px;
  height: 56px;
  border: none;
  border-radius: 50%;
  background: var(--zw-header-bg);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.22);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: zw-breathe 3s ease-in-out infinite;
}

.zw-fab:hover {
  transform: scale(1.06);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.28);
}

.zw-fab.is-hidden {
  display: none;
}

.zw-fab svg {
  width: 28px;
  height: 28px;
}

.zw-fab__badge {
  position: absolute;
  top: 2px;
  right: 2px;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: #ff3b30;
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  line-height: 18px;
  text-align: center;
  border: 2px solid #fff;
  display: none;
}

.zw-fab__badge.is-show {
  display: block;
}

@keyframes zw-breathe {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.05);
  }
}

/* 欢迎预览气泡 */
.zw-preview {
  position: fixed;
  right: 92px;
  bottom: 88px;
  max-width: 240px;
  padding: 10px 14px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.12);
  font-size: 13px;
  line-height: 1.5;
  color: #333;
  opacity: 0;
  visibility: hidden;
  transform: translateX(8px);
  transition: opacity 0.3s ease, transform 0.3s ease, visibility 0.3s;
  pointer-events: none;
}

.zw-preview::after {
  content: "";
  position: absolute;
  right: -6px;
  bottom: 18px;
  width: 12px;
  height: 12px;
  background: #fff;
  transform: rotate(45deg);
  box-shadow: 2px -2px 4px rgba(0, 0, 0, 0.06);
}

.zw-preview.is-show {
  opacity: 1;
  visibility: visible;
  transform: translateX(0);
}

.zw-preview.is-hidden {
  display: none;
}

/* 遮罩 */
.zw-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  visibility: hidden;
  transition: opacity 0.25s ease, visibility 0.25s;
}

.zw-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}

/* 聊天面板 */
.zw-panel {
  position: fixed;
  right: 24px;
  bottom: 80px;
  width: 380px;
  height: 520px;
  max-height: calc(100vh - 100px);
  display: flex;
  flex-direction: column;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.15);
  overflow: hidden;
  opacity: 0;
  visibility: hidden;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.28s ease, transform 0.28s ease, visibility 0.28s;
}

.zw-panel.is-open {
  opacity: 1;
  visibility: visible;
  transform: translateY(0) scale(1);
}

.zw-panel__head {
  flex-shrink: 0;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px 0 14px;
  background: var(--zw-header-bg);
  color: #fff;
}

.zw-panel__who {
  display: flex;
  align-items: center;
  gap: 10px;
}

.zw-panel__avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  border: 2px solid rgba(255, 255, 255, 0.85);
  background: #fff;
}

.zw-panel__name {
  font-size: 15px;
  font-weight: 600;
}

.zw-panel__status {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  opacity: 0.92;
  margin-top: 2px;
}

.zw-panel__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #4ade80;
}

.zw-panel__min {
  border: none;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.zw-panel__min:hover {
  background: rgba(255, 255, 255, 0.32);
}

.zw-panel__body {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  background: #f7f7f7;
  -webkit-overflow-scrolling: touch;
}

.zw-msg-time {
  text-align: center;
  font-size: 11px;
  color: #999;
  margin: 8px 0;
}

.zw-msg-row {
  display: flex;
  margin-bottom: 10px;
}

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

.zw-msg-row--ai {
  justify-content: flex-start;
}

.zw-msg-bubble {
  max-width: 75%;
  padding: 10px 12px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.55;
  white-space: pre-wrap;
  word-break: break-word;
}

.zw-msg-row--ai .zw-msg-bubble {
  background: #fff;
  color: #1a1a1a;
  border-radius: 4px 12px 12px 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
}

.zw-msg-row--user .zw-msg-bubble {
  background: var(--zw-user-bg);
  color: #1a1a1a;
  border-radius: 12px 4px 12px 12px;
}

.zw-msg-link {
  color: var(--zw-primary);
  text-decoration: underline;
  word-break: break-all;
}

.zw-msg-link:hover {
  opacity: 0.85;
}

.zw-card-link {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding: 10px 12px;
  border-radius: 10px;
  background: linear-gradient(135deg, #fff5f5 0%, #fff 100%);
  border: 1px solid rgba(229, 57, 53, 0.25);
  color: #1a1a1a;
  text-decoration: none;
  box-shadow: 0 2px 8px rgba(229, 57, 53, 0.08);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.zw-card-link:hover {
  transform: translateY(-1px);
  box-shadow: 0 4px 12px rgba(229, 57, 53, 0.14);
}

.zw-card-link__icon {
  flex-shrink: 0;
  font-size: 22px;
  line-height: 1;
}

.zw-card-link__body {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.zw-card-link__title {
  font-size: 14px;
  font-weight: 600;
  color: var(--zw-primary-dark);
}

.zw-card-link__sub {
  font-size: 12px;
  color: #666;
}

.zw-typing {
  display: inline-flex;
  gap: 4px;
  padding: 12px 14px;
  background: #fff;
  border-radius: 4px 12px 12px 12px;
}

.zw-typing span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #bbb;
  animation: zw-dot 1.2s ease-in-out infinite;
}

.zw-typing span:nth-child(2) {
  animation-delay: 0.15s;
}

.zw-typing span:nth-child(3) {
  animation-delay: 0.3s;
}

@keyframes zw-dot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.5;
  }
  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

.zw-panel__foot {
  flex-shrink: 0;
  border-top: 1px solid #eee;
  background: #fff;
  padding: 8px 10px;
  padding-bottom: max(8px, env(safe-area-inset-bottom));
}

.zw-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  min-height: 52px;
}

.zw-input-row textarea {
  flex: 1;
  min-width: 0;
  max-height: 88px;
  resize: none;
  border: 1px solid #e5e5e5;
  border-radius: 20px;
  padding: 10px 14px;
  font-size: 14px;
  line-height: 1.4;
  font-family: inherit;
  outline: none;
}

.zw-input-row textarea:focus {
  border-color: var(--zw-primary);
}

.zw-send {
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  border: none;
  border-radius: 50%;
  background: var(--zw-primary);
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
}

.zw-send:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.zw-send svg {
  width: 18px;
  height: 18px;
}

.zw-material {
  display: block;
  margin-top: 6px;
  text-align: center;
  font-size: 12px;
  color: var(--zw-primary);
  text-decoration: none;
}

.zw-material:hover {
  text-decoration: underline;
}

/* 移动端 */
@media (max-width: 767px) {
  .zw-fab {
    right: 16px;
    bottom: 72px;
  }

  .zw-preview {
    right: 16px;
    left: 16px;
    bottom: 140px;
    max-width: none;
  }

  .zw-preview::after {
    display: none;
  }

  .zw-panel {
    left: 0;
    right: 0;
    bottom: 0;
    width: 100%;
    height: 70vh;
    max-height: 70vh;
    border-radius: 12px 12px 0 0;
  }

  .zw-backdrop.is-open {
    display: block;
  }
}

@media (min-width: 768px) {
  .zw-backdrop {
    display: none;
  }
}

/* 与标准底栏 contact-footer 共存（各页可在 :root 覆盖 --contact-footer-h） */
body.has-contact-footer {
  --contact-footer-h: 92px;
}

body.has-contact-footer .zw-root .zw-fab {
  bottom: calc(var(--contact-footer-h) + 12px + env(safe-area-inset-bottom));
}

body.has-contact-footer .zw-root .zw-preview {
  bottom: calc(var(--contact-footer-h) + 20px + env(safe-area-inset-bottom));
}

body.has-contact-footer.has-cta-stack .zw-root .zw-fab {
  bottom: calc(
    var(--contact-footer-h) + var(--cta-bar-h, 68px) + 12px + env(safe-area-inset-bottom)
  );
}

@media (min-width: 768px) {
  body.has-contact-footer .zw-root .zw-panel {
    bottom: calc(var(--contact-footer-h) + 12px + env(safe-area-inset-bottom));
  }
}

@media (max-width: 767px) {
  body.has-contact-footer .zw-root .zw-preview {
    right: 16px;
    left: 16px;
    bottom: calc(var(--contact-footer-h) + 56px + env(safe-area-inset-bottom));
    max-width: none;
  }
}
