/* QiuQ Bot — full-screen frosted chat. Scoped to #chat-app. */

#chat-app {
  position: fixed;
  inset: 0;
  z-index: 20;
  width: 100%;
  height: 100%;
  max-width: 390px;
  max-height: 844px;
  margin: auto;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  padding:
    env(safe-area-inset-top, 0px)
    env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px)
    env(safe-area-inset-left, 0px);
  overflow: hidden;
  color: #3f3958;
  font-family: "Noto Sans CJK SC", "Noto Sans", sans-serif;
  background:
    linear-gradient(165deg, rgba(226, 219, 237, 0.82) 0%, rgba(255, 255, 255, 0.62) 42%, rgba(121, 167, 217, 0.38) 100%);
  backdrop-filter: blur(28px) saturate(1.45);
  -webkit-backdrop-filter: blur(28px) saturate(1.45);
  box-shadow: 0 18px 50px rgba(154, 142, 195, 0.28);
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

#chat-app[hidden] {
  display: none !important;
}

#chat-app.is-open {
  animation: chatIn 0.32s cubic-bezier(0.22, 1, 0.36, 1);
}

#chat-app *,
#chat-app *::before,
#chat-app *::after {
  box-sizing: border-box;
}

.chat-top {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 10px 12px 8px;
  background: rgba(255, 255, 255, 0.42);
  border-bottom: 1px solid rgba(255, 255, 255, 0.62);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(18px) saturate(1.3);
  -webkit-backdrop-filter: blur(18px) saturate(1.3);
}

.chat-back {
  flex: none;
  width: 36px;
  height: 36px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: #3f3958;
  background: rgba(255, 255, 255, 0.62);
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow: 0 4px 12px rgba(154, 142, 195, 0.16);
}

.chat-back:active {
  transform: scale(0.96);
}

.chat-back svg {
  display: block;
}

.chat-avatar {
  flex: none;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: #e2dbed;
  border: 2px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 4px 12px rgba(121, 167, 217, 0.28);
}

.chat-id {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.chat-name {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.02em;
  line-height: 1.2;
  color: #3f3958;
}

.chat-status {
  margin: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  line-height: 1.2;
  color: #645b86;
}

.chat-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #79a7d9;
  box-shadow: 0 0 0 3px rgba(121, 167, 217, 0.22);
  animation: chatPulse 1.8s ease-in-out infinite;
}

.chat-list {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 54px 14px 12px;
}

.chat-row {
  position: relative;
  display: flex;
  flex-direction: column;
  max-width: 100%;
  animation: chatPop 0.28s cubic-bezier(0.22, 1, 0.36, 1) both;
}

.chat-row.user {
  align-items: flex-end;
}

.chat-row.bot {
  align-items: flex-start;
}

.chat-bubble {
  max-width: 78%;
  padding: 10px 13px;
  border-radius: 18px;
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  white-space: pre-wrap;
}

.chat-row.user .chat-bubble {
  border-bottom-right-radius: 6px;
  color: #ffffff;
  background: rgba(121, 167, 217, 0.88);
  border: 1px solid rgba(255, 255, 255, 0.38);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.42),
    0 8px 18px rgba(121, 167, 217, 0.22);
  backdrop-filter: blur(14px) saturate(1.35);
  -webkit-backdrop-filter: blur(14px) saturate(1.35);
}

.chat-row.bot .chat-bubble {
  border-bottom-left-radius: 6px;
  color: #3f3958;
  background: rgba(255, 255, 255, 0.5);
  border: 1px solid rgba(255, 255, 255, 0.74);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.85),
    0 8px 18px rgba(154, 142, 195, 0.12);
  backdrop-filter: blur(16px) saturate(1.25);
  -webkit-backdrop-filter: blur(16px) saturate(1.25);
}

.chat-foot {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 4px;
  min-height: 16px;
}

.chat-row time {
  font-size: 10px;
  line-height: 1.2;
  letter-spacing: 0.02em;
  color: #645b86;
}

.chat-react-chip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid rgba(255, 255, 255, 0.86);
  box-shadow: 0 4px 10px rgba(154, 142, 195, 0.16);
  font-size: 13px;
  line-height: 1;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.chat-react-chip[hidden] {
  display: none !important;
}

.chat-reactbar {
  position: absolute;
  bottom: calc(100% + 6px);
  z-index: 3;
  display: flex;
  gap: 2px;
  padding: 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.9);
  box-shadow: 0 10px 24px rgba(154, 142, 195, 0.28);
  backdrop-filter: blur(16px) saturate(1.3);
  -webkit-backdrop-filter: blur(16px) saturate(1.3);
}

.chat-reactbar[hidden] {
  display: none !important;
}

.chat-row.user .chat-reactbar {
  right: 0;
}

.chat-row.bot .chat-reactbar {
  left: 0;
}

.chat-reactbar button {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  line-height: 1;
  background: transparent;
}

.chat-reactbar button.is-on,
.chat-reactbar button:active {
  background: rgba(121, 167, 217, 0.28);
}

.chat-typing .chat-bubble {
  display: flex;
  align-items: center;
  gap: 5px;
  min-width: 58px;
  min-height: 38px;
  padding: 12px 14px;
}

.chat-typing i {
  display: block;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9a8ec3;
  animation: chatDot 1s infinite ease-in-out;
}

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

.chat-typing i:nth-child(3) {
  animation-delay: 0.3s;
  background: #79a7d9;
}

.chat-compose {
  flex: none;
  padding: 4px 12px 12px;
}

.chat-tray {
  display: flex;
  gap: 8px;
  padding: 2px 4px 8px;
}

.chat-tray[hidden] {
  display: none !important;
}

.chat-chip {
  flex: 1 1 0;
  min-width: 0;
  height: 36px;
  border-radius: 14px;
  font-size: 13px;
  font-weight: 600;
  color: #3f3958;
  background: rgba(255, 255, 255, 0.52);
  border: 1px solid rgba(255, 255, 255, 0.75);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.chat-chip:active {
  transform: scale(0.98);
}

.chat-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  min-height: 52px;
  padding: 6px 6px 6px 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.58);
  border: 1px solid rgba(255, 255, 255, 0.78);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.9),
    0 10px 22px rgba(121, 167, 217, 0.16);
  backdrop-filter: blur(18px) saturate(1.35);
  -webkit-backdrop-filter: blur(18px) saturate(1.35);
}

.chat-plus,
.chat-send {
  flex: none;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: grid;
  place-items: center;
}

.chat-plus {
  font-size: 26px;
  line-height: 1;
  font-weight: 400;
  color: #3f3958;
  background: rgba(226, 219, 237, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.8);
}

.chat-plus[aria-expanded="true"] {
  background: rgba(154, 142, 195, 0.35);
}

.chat-plus:active,
.chat-send:active {
  transform: scale(0.96);
}

.chat-input {
  flex: 1 1 auto;
  min-width: 0;
  height: 38px;
  margin: 0;
  padding: 0 4px;
  border: 0;
  outline: none;
  background: transparent;
  color: #3f3958;
  font: inherit;
  font-size: 16px;
  line-height: 1.3;
  -webkit-user-select: text;
  user-select: text;
}

.chat-input::placeholder {
  color: #645b86;
  opacity: 0.85;
}

.chat-send {
  color: #ffffff;
  background: linear-gradient(160deg, #9a8ec3 0%, #79a7d9 100%);
  box-shadow: 0 6px 14px rgba(121, 167, 217, 0.32);
}

.chat-send svg {
  display: block;
  margin-left: 1px;
}

@keyframes chatIn {
  from {
    opacity: 0;
    transform: translateY(16px) scale(0.985);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes chatPop {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

@keyframes chatDot {
  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: 0.35;
  }
  40% {
    transform: translateY(-3px);
    opacity: 1;
  }
}

@keyframes chatPulse {
  0%,
  100% {
    box-shadow: 0 0 0 3px rgba(121, 167, 217, 0.18);
  }
  50% {
    box-shadow: 0 0 0 5px rgba(121, 167, 217, 0.08);
  }
}

@media (prefers-reduced-motion: reduce) {
  #chat-app.is-open,
  .chat-row,
  .chat-typing i,
  .chat-dot {
    animation: none !important;
  }
}
