/* ============================================================
   ULTRAINFRA — CHAT WIDGET
   chat-widget.css
   Built on the site's existing design tokens (tokens.css).
   Load tokens.css before this file.
   ============================================================ */

#ui-chat-launcher {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: var(--shadow-card);
  z-index: 8500;
  transition: transform 0.3s var(--ease-out), box-shadow 0.3s var(--ease-out);
}

#ui-chat-launcher:hover {
  transform: scale(1.06);
  box-shadow: var(--shadow-active);
}

#ui-chat-launcher svg {
  width: 24px;
  height: 24px;
  stroke: var(--fg-dark);
}

#ui-chat-launcher .ui-chat-dot {
  position: absolute;
  top: 4px;
  right: 4px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--accent-2);
  border: 2px solid var(--dark);
  display: none;
}

#ui-chat-launcher.has-unread .ui-chat-dot {
  display: block;
}

#ui-chat-panel {
  position: fixed;
  bottom: 92px;
  right: 24px;
  width: 368px;
  max-width: calc(100vw - 32px);
  height: 520px;
  max-height: calc(100vh - 140px);
  background: var(--dark);
  border: var(--rule-dark);
  border-radius: 16px;
  box-shadow: var(--shadow-card);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 8500;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.28s var(--ease-out), transform 0.28s var(--ease-out);
  font-family: var(--font);
}

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

#ui-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: var(--rule-dark);
  background: var(--surface);
}

#ui-chat-header-title {
  font-family: var(--font-display);
  font-size: 1rem;
  letter-spacing: var(--ls-tight);
  color: var(--fg-dark);
  margin: 0;
}

#ui-chat-header-subtitle {
  font-size: var(--text-caption);
  letter-spacing: var(--ls-label);
  text-transform: uppercase;
  color: var(--mid-dark);
  margin: 2px 0 0;
}

#ui-chat-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--fg-dark);
  opacity: 0.6;
  width: 28px;
  height: 28px;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: opacity 0.2s var(--ease-out);
}

#ui-chat-close:hover {
  opacity: 1;
}

#ui-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

#ui-chat-messages::-webkit-scrollbar {
  width: 6px;
}

#ui-chat-messages::-webkit-scrollbar-thumb {
  background: var(--border-dark);
  border-radius: 3px;
}

.ui-chat-msg {
  max-width: 82%;
  font-size: var(--text-body-sm);
  line-height: var(--lh-body);
  padding: 10px 13px;
  border-radius: 12px;
  word-wrap: break-word;
  white-space: pre-wrap;
}

.ui-chat-msg.bot {
  align-self: flex-start;
  background: var(--surface);
  border: var(--rule-dark);
  color: var(--fg-dark);
  border-bottom-left-radius: 4px;
}

.ui-chat-msg.user {
  align-self: flex-end;
  background: var(--accent);
  color: var(--fg-dark);
  border-bottom-right-radius: 4px;
}

.ui-chat-msg.error {
  align-self: flex-start;
  background: rgba(255,89,73,0.12);
  border: 1px solid rgba(255,89,73,0.3);
  color: var(--fg-dark);
}

#ui-chat-typing {
  align-self: flex-start;
  display: none;
  gap: 4px;
  padding: 12px 13px;
  background: var(--surface);
  border: var(--rule-dark);
  border-radius: 12px;
  border-bottom-left-radius: 4px;
}

#ui-chat-typing.visible {
  display: flex;
}

#ui-chat-typing span {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--mid-dark);
  animation: ui-chat-bounce 1.2s infinite ease-in-out;
}

#ui-chat-typing span:nth-child(2) { animation-delay: 0.15s; }
#ui-chat-typing span:nth-child(3) { animation-delay: 0.3s; }

@keyframes ui-chat-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

#ui-chat-form {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 14px;
  border-top: var(--rule-dark);
  background: var(--surface);
}

#ui-chat-input {
  flex: 1;
  background: var(--dark);
  border: var(--rule-dark);
  border-radius: 20px;
  padding: 10px 14px;
  color: var(--fg-dark);
  font-family: var(--font);
  font-size: var(--text-body-sm);
  outline: none;
  transition: border-color 0.2s var(--ease-out);
}

#ui-chat-input:focus {
  border-color: var(--accent);
}

#ui-chat-input::placeholder {
  color: var(--mid-dark);
}

#ui-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 0.2s var(--ease-out);
}

#ui-chat-send:disabled {
  opacity: 0.4;
  cursor: default;
}

#ui-chat-send svg {
  width: 16px;
  height: 16px;
  stroke: var(--fg-dark);
}

@media (max-width: 480px) {
  #ui-chat-panel {
    right: 16px;
    left: 16px;
    width: auto;
    bottom: 88px;
  }
  #ui-chat-launcher {
    right: 16px;
    bottom: 16px;
  }
}
