/* Chat widget is always visible regardless of page transitions */
#sh-chat-btn,
#sh-chat-panel {
  isolation: isolate;
}

/* Toggle button */
#sh-chat-btn {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: #4f8eff;
  border: none;
  cursor: pointer;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(79,142,255,0.45);
  transition: transform 200ms ease,
    box-shadow 200ms ease;
  opacity: 0;
  animation: chatBtnAppear 600ms ease 800ms
    forwards;
}

@keyframes chatBtnAppear {
  from {
    opacity: 0;
    transform: scale(0.8) translateY(8px);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}
/* Guard against any page-transition CSS accidentally hiding the button.
   Opacity is NOT forced here - it is owned by the chatBtnAppear entrance
   animation below (a forced !important opacity would beat the animation's
   keyframes in the cascade and make the fade-in inert). */
#sh-chat-btn {
  visibility: visible !important;
  display: flex !important;
}
#sh-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(79,142,255,0.6);
}
#sh-chat-btn svg {
  width: 22px;
  height: 22px;
  fill: #ffffff;
  transition: transform 200ms ease,
    opacity 200ms ease;
}
#sh-chat-btn .ico-open {
  position: absolute;
}
#sh-chat-btn .ico-close {
  position: absolute;
  opacity: 0;
  transform: rotate(-90deg) scale(0.5);
}
#sh-chat-btn.is-open .ico-open {
  opacity: 0;
  transform: rotate(90deg) scale(0.5);
}
#sh-chat-btn.is-open .ico-close {
  opacity: 1;
  transform: rotate(0deg) scale(1);
}

/* Panel */
#sh-chat-panel {
  position: fixed;
  bottom: 90px;
  right: 24px;
  width: 340px;
  height: 500px;
  background: #111111;
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 9999;
  box-shadow: 0 20px 60px rgba(0,0,0,0.6);
  opacity: 0;
  transform: translateY(16px) scale(0.97);
  pointer-events: none;
  transition: opacity 220ms ease,
    transform 220ms cubic-bezier(0.16,1,0.3,1);
}
#sh-chat-panel.is-open {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: all;
}

/* Header */
.chat-header {
  flex-shrink: 0;
  padding: 14px 16px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(79,142,255,0.05);
}
.chat-header .chat-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: linear-gradient(
    135deg, #4f8eff, #38bdf8
  );
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  flex-shrink: 0;
}
.chat-header .chat-name {
  font-size: 13px;
  font-weight: 600;
  color: #ffffff;
  font-family: inherit;
}
.chat-header .chat-status {
  font-size: 11px;
  color: #a0a0a0;
  display: flex;
  align-items: center;
  gap: 5px;
}
.chat-header .chat-status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #22c55e;
  flex-shrink: 0;
}

/* Messages */
#sh-chat-messages {
  flex: 1 1 0;
  min-height: 0;
  overflow-y: auto;
  padding: 14px 14px 8px 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scroll-behavior: smooth;
}
#sh-chat-messages::-webkit-scrollbar {
  width: 3px;
}
#sh-chat-messages::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.1);
  border-radius: 2px;
}
.chat-msg {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  max-width: 88%;
}
.chat-msg.is-bot {
  align-self: flex-start;
}
.chat-msg.is-user {
  align-self: flex-end;
  flex-direction: row-reverse;
}
.chat-msg .msg-bubble {
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.55;
  color: #ffffff;
  font-family: inherit;
}
.chat-msg.is-bot .msg-bubble {
  background: rgba(255,255,255,0.06);
  border: 1px solid rgba(255,255,255,0.08);
  border-bottom-left-radius: 4px;
}
.chat-msg.is-user .msg-bubble {
  background: rgba(79,142,255,0.2);
  border: 1px solid rgba(79,142,255,0.3);
  border-bottom-right-radius: 4px;
  color: #ffffff;
}
.msg-avatar {
  width: 24px;
  height: 24px;
  border-radius: 50%;
  background: linear-gradient(
    135deg, #4f8eff, #38bdf8
  );
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
}

/* Typing indicator */
.chat-typing {
  display: flex;
  gap: 4px;
  align-items: center;
  padding: 10px 13px;
}
.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: rgba(79,142,255,0.6);
  animation: typingBounce 1s
    ease-in-out infinite;
}
.typing-dot:nth-child(2) {
  animation-delay: 0.15s;
}
.typing-dot:nth-child(3) {
  animation-delay: 0.3s;
}
@keyframes typingBounce {
  0%,60%,100% { transform: translateY(0); }
  30% { transform: translateY(-5px); }
}

/* Suggestion buttons */
#sh-chat-suggestions {
  flex: 0 0 auto;
  padding: 6px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 5px;
  border-top: 1px solid rgba(255,255,255,0.05);
  background: #111111;
}
.chat-suggestion {
  background: rgba(79,142,255,0.08);
  border: 1px solid rgba(79,142,255,0.2);
  border-radius: 6px;
  padding: 9px 13px;
  font-size: 12.5px;
  color: #4f8eff;
  cursor: pointer;
  text-align: left;
  width: 100%;
  display: block;
  font-family: inherit;
  line-height: 1.4;
  pointer-events: all;
  transition: background 150ms ease,
    border-color 150ms ease;
}
.chat-suggestion:hover {
  background: rgba(79,142,255,0.16);
  border-color: rgba(79,142,255,0.4);
  color: #b8d0ff;
}

/* Footer */
.chat-footer {
  flex: 0 0 auto;
  padding: 6px 14px 8px;
  border-top: 1px solid rgba(255,255,255,0.05);
  font-size: 10px;
  color: #a0a0a0;
  text-align: center;
  font-family: monospace;
}

/* Mobile */
@media (max-width: 768px) {
  #sh-chat-btn {
    width: 48px;
    height: 48px;
    bottom: 16px;
    right: 16px;
  }
}

@media (max-width: 480px) {
  #sh-chat-panel {
    right: 12px;
    left: 12px;
    width: auto;
    bottom: 84px;
  }
  #sh-chat-btn {
    right: 16px;
    bottom: 16px;
  }
}
