/* ══════════════════════════════════════════════════
   Club222 AI Chat Widget — chat.css
══════════════════════════════════════════════════ */

/* ── Floating button ── */
#c222-chat-btn {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 9999;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #7B3FA0;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  box-shadow: 0 2px 12px rgba(123, 63, 160, 0.35);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
  animation: c222-breathe 2.4s ease-in-out infinite;
  outline: none;
  -webkit-tap-highlight-color: transparent;
}

#c222-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 22px rgba(123, 63, 160, 0.55) !important;
  animation-play-state: paused;
}

/* Breathing glow — dark halo pulses every 2.4s */
@keyframes c222-breathe {
  0%, 100% {
    box-shadow:
      0 0 0 0   rgba(26, 26, 24, 0.0),
      0 2px 12px rgba(26, 26, 24, 0.25);
  }
  50% {
    box-shadow:
      0 0 0 9px rgba(26, 26, 24, 0.08),
      0 2px 22px rgba(26, 26, 24, 0.35);
  }
}

/* ── Tooltip bubble ── */
#c222-tooltip {
  position: fixed;
  bottom: 82px;
  right: 16px;
  z-index: 9998;
  background: #ffffff;
  color: #4a1fa8;
  font-size: 13px;
  font-weight: 600;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  padding: 8px 14px;
  border-radius: 20px;
  border: 1px solid rgba(108, 63, 212, 0.28);
  box-shadow: 0 4px 18px rgba(108, 63, 212, 0.16);
  white-space: nowrap;
  pointer-events: none;
  opacity: 0;
  transform: translateY(6px);
  transition: opacity 0.3s ease, transform 0.3s ease;
}

#c222-tooltip.visible {
  opacity: 1;
  transform: translateY(0);
}

/* Arrow pointing down-right */
#c222-tooltip::after {
  content: '';
  position: absolute;
  bottom: -6px;
  right: 20px;
  width: 11px;
  height: 11px;
  background: #ffffff;
  border-right: 1px solid rgba(108, 63, 212, 0.28);
  border-bottom: 1px solid rgba(108, 63, 212, 0.28);
  transform: rotate(45deg);
}

/* ── Chat dialog ── */
#c222-chat-dialog {
  position: fixed;
  bottom: 82px;
  right: 20px;
  z-index: 9997;
  width: 360px;
  height: 500px;
  background: #ffffff;
  border-radius: 16px;
  border: 1px solid rgba(108, 63, 212, 0.18);
  box-shadow:
    0 8px 40px rgba(108, 63, 212, 0.16),
    0 2px 18px rgba(0, 0, 0, 0.10);
  display: flex;
  flex-direction: column;
  overflow: hidden;

  /* Hidden state */
  opacity: 0;
  transform: translateY(14px) scale(0.96);
  transform-origin: bottom right;
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
}

#c222-chat-dialog.open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

/* ── Header ── */
.c222-header {
  background: linear-gradient(135deg, #6C3FD4 0%, #8B5CF6 100%);
  padding: 13px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  user-select: none;
}

.c222-header-title {
  color: #ffffff;
  font-size: 14px;
  font-weight: 700;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  display: flex;
  align-items: center;
  gap: 7px;
  line-height: 1;
}

.c222-close-btn {
  background: transparent;
  border: none;
  color: rgba(255, 255, 255, 0.75);
  cursor: pointer;
  padding: 3px;
  border-radius: 5px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color 0.2s, background 0.2s;
  line-height: 1;
}

.c222-close-btn:hover {
  color: #ffffff;
  background: rgba(255, 255, 255, 0.15);
}

/* ── Messages area ── */
.c222-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}

.c222-messages::-webkit-scrollbar {
  width: 4px;
}
.c222-messages::-webkit-scrollbar-track {
  background: transparent;
}
.c222-messages::-webkit-scrollbar-thumb {
  background: rgba(108, 63, 212, 0.25);
  border-radius: 2px;
}

/* ── Message bubble ── */
.c222-msg {
  max-width: 86%;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  line-height: 1.6;
  padding: 9px 12px;
  border-radius: 12px;
  word-break: break-word;
  white-space: pre-wrap;
}

.c222-msg.assistant {
  background: #f0eaff;
  color: #2d1a6e;
  border-bottom-left-radius: 3px;
  align-self: flex-start;
}

.c222-msg.user {
  background: #6C3FD4;
  color: #ffffff;
  border-bottom-right-radius: 3px;
  align-self: flex-end;
}

/* Loading dots bubble */
.c222-msg.loading {
  background: #f0eaff;
  color: #9876d4;
  align-self: flex-start;
  border-bottom-left-radius: 3px;
  min-width: 52px;
  text-align: center;
}

.c222-dots {
  display: inline-flex;
  gap: 3px;
  align-items: center;
}

.c222-dots span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #9876d4;
  opacity: 0;
  animation: c222-dot-fade 1.2s infinite ease-in-out;
}

.c222-dots span:nth-child(1) { animation-delay: 0s; }
.c222-dots span:nth-child(2) { animation-delay: 0.18s; }
.c222-dots span:nth-child(3) { animation-delay: 0.36s; }

@keyframes c222-dot-fade {
  0%, 80%, 100% { opacity: 0.15; transform: scale(0.8); }
  40%           { opacity: 1;    transform: scale(1); }
}

/* ── Input area ── */
.c222-input-area {
  border-top: 1px solid rgba(108, 63, 212, 0.10);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  align-items: flex-end;
  flex-shrink: 0;
  background: #fafafa;
}

#c222-input {
  flex: 1;
  border: 1px solid rgba(108, 63, 212, 0.22);
  border-radius: 10px;
  padding: 8px 11px;
  font-size: 13px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #1a1a2e;
  background: #ffffff;
  resize: none;
  outline: none;
  min-height: 36px;
  max-height: 80px;
  line-height: 1.45;
  transition: border-color 0.2s, box-shadow 0.2s;
  box-sizing: border-box;
}

#c222-input:focus {
  border-color: #6C3FD4;
  box-shadow: 0 0 0 3px rgba(108, 63, 212, 0.10);
}

#c222-input::placeholder {
  color: #aaa;
}

#c222-send-btn {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  background: #6C3FD4;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.15s;
  padding: 0;
}

#c222-send-btn:hover:not(:disabled) {
  background: #5a32b0;
  transform: scale(1.06);
}

#c222-send-btn:disabled {
  background: #c4b5fd;
  cursor: not-allowed;
  transform: none;
}

/* ── Suggest button ── */
.c222-suggest-wrap {
  margin-top: 8px;
}

.c222-suggest-btn {
  display: inline-block;
  background: #6C3FD4;
  color: #ffffff;
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-weight: 500;
  line-height: 1.4;
  padding: 6px 12px;
  border: none;
  border-radius: 20px;
  cursor: pointer;
  text-align: left;
  transition: background 0.2s, transform 0.15s;
  white-space: normal;
  word-break: break-word;
}

.c222-suggest-btn:hover {
  background: #5a32b0;
  transform: scale(1.03);
}

.c222-wechat-btn {
  display: inline-block;
  background: #07C160;
  color: #ffffff;
  font-size: 12px;
  font-family: -apple-system, BlinkMacSystemFont, "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-weight: 500;
  line-height: 1.4;
  padding: 6px 14px;
  border-radius: 20px;
  text-decoration: none;
  transition: background 0.2s, transform 0.15s;
  white-space: nowrap;
}

.c222-wechat-btn:hover {
  background: #06ad56;
  transform: scale(1.03);
  color: #ffffff;
}

/* ── Mobile: lift above bottom tabbar (visible at ≤768px, height 56px + safe-area) ── */
@media (max-width: 768px) {
  #c222-chat-btn {
    bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 16px);
  }
  #c222-tooltip {
    bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 80px);
  }
  #c222-chat-dialog {
    bottom: calc(56px + env(safe-area-inset-bottom, 0px) + 80px);
  }
}

/* ── Mobile small: full-width dialog ── */
@media (max-width: 480px) {
  #c222-chat-dialog {
    width: 90vw;
    height: 70vh;
    right: 5vw;
    border-radius: 16px;
    transform-origin: bottom center;
  }
  #c222-tooltip {
    right: 10px;
  }
}
