/* ==========================================================================
   数嘉科技 · WebSocket chat widget
   Works on the new site and the legacy contact page.
   ========================================================================== */

.sjchat {
  --sjchat-ink: #071417;
  --sjchat-paper: #f7f2e8;
  --sjchat-paper-2: #fffdf8;
  --sjchat-line: #e5dccd;
  --sjchat-muted: #7d7568;
  --sjchat-accent: #f56a12;
  --sjchat-green: #19b97a;
  position: fixed;
  right: 26px;
  bottom: 24px;
  z-index: 260;
  color: #253044;
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  transition: opacity 0.2s ease, visibility 0.2s ease;
}

.sj-lock .sjchat,
.menu-open .sjchat,
.xm-menu-open .sjchat {
  opacity: 0;
  visibility: hidden;
  pointer-events: none;
}

.sjchat * {
  box-sizing: border-box;
}

.sjchat-fab {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 9px;
  min-height: 54px;
  padding: 0 18px 0 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 999px;
  background: var(--sjchat-ink);
  color: #f7f2e8;
  box-shadow: 0 18px 44px rgba(7, 20, 23, 0.24);
  font-size: 13px;
  font-weight: 600;
  letter-spacing: 0.02em;
  cursor: pointer;
  transition: transform 0.2s ease, opacity 0.2s ease, box-shadow 0.2s ease;
}

.sjchat-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 24px 52px rgba(7, 20, 23, 0.3);
}

.sjchat-fab-icon {
  position: relative;
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--sjchat-accent);
  color: #fff;
  flex: none;
}

.sjchat-fab-icon::after {
  position: absolute;
  top: -1px;
  right: -1px;
  width: 9px;
  height: 9px;
  content: "";
  border: 2px solid var(--sjchat-ink);
  border-radius: 50%;
  background: var(--sjchat-green);
  animation: sjchatPulse 2.2s ease-in-out infinite;
}

.sjchat-fab-icon svg {
  width: 18px;
  height: 18px;
}

.sjchat-unread {
  position: absolute;
  top: 5px;
  right: 8px;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--sjchat-accent);
  box-shadow: 0 0 0 2px var(--sjchat-ink);
}

.sjchat-panel {
  position: absolute;
  right: 0;
  bottom: 68px;
  display: flex;
  flex-direction: column;
  width: 386px;
  height: min(560px, calc(100vh - 120px));
  border: 1px solid rgba(7, 20, 23, 0.1);
  border-radius: 20px;
  background: var(--sjchat-paper);
  box-shadow: 0 30px 80px rgba(7, 20, 23, 0.24);
  opacity: 0;
  visibility: hidden;
  transform: translateY(12px) scale(0.98);
  transform-origin: bottom right;
  overflow: hidden;
  transition: opacity 0.22s ease, transform 0.22s ease, visibility 0.22s ease;
}

.sjchat.is-open .sjchat-panel {
  opacity: 1;
  visibility: visible;
  transform: none;
}

.sjchat.is-open .sjchat-fab {
  opacity: 0;
  pointer-events: none;
  transform: translateY(5px);
}

.sjchat-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 14px 13px;
  background: var(--sjchat-ink);
  color: #f7f2e8;
}

.sjchat-avatar {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border-radius: 11px;
  background: #fff7ef;
  flex: none;
}

.sjchat-avatar img {
  width: 30px;
  height: 30px;
  object-fit: contain;
}

.sjchat-who {
  min-width: 0;
  flex: 1;
}

.sjchat-who strong {
  display: block;
  color: #fff;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.4;
}

.sjchat-status {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 2px;
  color: rgba(247, 242, 232, 0.6);
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 9.5px;
  letter-spacing: 0.03em;
}

.sjchat-status i {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #d6a23e;
  flex: none;
}

.sjchat-status.is-online i {
  background: var(--sjchat-green);
  box-shadow: 0 0 0 3px rgba(25, 185, 122, 0.16);
}

.sjchat-status.is-demo i {
  background: #d6a23e;
}

.sjchat-close {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 50%;
  background: transparent;
  color: #f7f2e8;
  cursor: pointer;
  flex: none;
}

.sjchat-close:hover {
  background: rgba(255, 255, 255, 0.08);
}

.sjchat-close svg {
  width: 14px;
  height: 14px;
}

.sjchat-body {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 11px;
  padding: 18px 15px 12px;
  overflow-y: auto;
  overscroll-behavior: contain;
  background:
    radial-gradient(circle at 88% 8%, rgba(245, 106, 18, 0.08), transparent 38%),
    var(--sjchat-paper);
}

.sjchat-msg {
  max-width: 84%;
  padding: 10px 12px;
  border: 1px solid var(--sjchat-line);
  border-radius: 12px 12px 12px 4px;
  background: var(--sjchat-paper-2);
  color: #3e4652;
  font-size: 12.5px;
  line-height: 1.7;
  white-space: pre-wrap;
  word-break: break-word;
}

.sjchat-msg--user {
  align-self: flex-end;
  border-color: var(--sjchat-ink);
  border-radius: 12px 12px 4px 12px;
  background: var(--sjchat-ink);
  color: #f7f2e8;
}

.sjchat-msg--system {
  max-width: 100%;
  align-self: center;
  padding: 4px 8px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: #9a9184;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 8.5px;
  text-align: center;
}

.sjchat-msg time {
  display: block;
  margin-top: 3px;
  color: #a8a195;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 8px;
}

.sjchat-msg--user time {
  color: rgba(247, 242, 232, 0.5);
  text-align: right;
}

.sjchat-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 2px;
}

.sjchat-chips button {
  padding: 5px 9px;
  border: 1px solid var(--sjchat-line);
  border-radius: 999px;
  background: var(--sjchat-paper-2);
  color: #756b5d;
  font: inherit;
  font-size: 10.5px;
  cursor: pointer;
  transition: border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}

.sjchat-chips button:hover {
  border-color: rgba(245, 106, 18, 0.45);
  background: #fff5eb;
  color: var(--sjchat-accent);
}

.sjchat-typing {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 16px 9px;
  color: #968d80;
  font-size: 9.5px;
}

.sjchat-typing[hidden] {
  display: none;
}

.sjchat-typing i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--sjchat-accent);
  animation: sjchatBounce 1.1s ease-in-out infinite;
}

.sjchat-typing i:nth-child(2) {
  animation-delay: 0.12s;
}

.sjchat-typing i:nth-child(3) {
  animation-delay: 0.24s;
}

.sjchat-typing span {
  margin-left: 3px;
}

.sjchat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--sjchat-line);
  background: var(--sjchat-paper-2);
}

.sjchat-form input {
  min-width: 0;
  flex: 1;
  height: 38px;
  padding: 0 11px;
  border: 1px solid var(--sjchat-line);
  border-radius: 9px;
  background: #fff;
  color: var(--sjchat-ink);
  font: inherit;
  font-size: 12px;
  outline: none;
}

.sjchat-form input:focus {
  border-color: rgba(245, 106, 18, 0.55);
  box-shadow: 0 0 0 3px rgba(245, 106, 18, 0.08);
}

.sjchat-form input::placeholder {
  color: #b0a89b;
}

.sjchat-form button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  border: 0;
  border-radius: 10px;
  background: var(--sjchat-accent);
  color: #fff;
  cursor: pointer;
  flex: none;
  transition: background 0.2s ease, transform 0.2s ease;
}

.sjchat-form button:hover {
  background: #e65300;
  transform: translateY(-1px);
}

.sjchat-form button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.sjchat-form svg {
  width: 16px;
  height: 16px;
}

.sjchat-foot {
  margin: 0;
  padding: 0 14px 10px;
  background: var(--sjchat-paper-2);
  color: #a59b8d;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 8px;
  line-height: 1.5;
  letter-spacing: 0.02em;
}

.sjchat.is-demo .sjchat-foot {
  color: #bd8d45;
}

@keyframes sjchatPulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(25, 185, 122, 0.25); }
  50% { box-shadow: 0 0 0 5px rgba(25, 185, 122, 0); }
}

@keyframes sjchatBounce {
  0%, 100% { transform: translateY(0); opacity: 0.45; }
  50% { transform: translateY(-3px); opacity: 1; }
}

@media (max-width: 620px) {
  .sjchat {
    right: 14px;
    bottom: 14px;
  }

  .sjchat-fab {
    min-height: 50px;
    padding-right: 15px;
    font-size: 12px;
  }

  .sjchat-fab-icon {
    width: 33px;
    height: 33px;
  }

  .sjchat-panel {
    position: fixed;
    right: 12px;
    bottom: 76px;
    left: 12px;
    width: auto;
    height: min(72vh, 560px);
    border-radius: 18px;
  }

  .sjchat-msg {
    font-size: 12px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sjchat-fab,
  .sjchat-panel,
  .sjchat-form button {
    transition-duration: 0.001ms;
  }

  .sjchat-fab-icon::after,
  .sjchat-typing i {
    animation: none;
  }
}
