.chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 9999px;
  background: var(--foreground);
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
  transition: transform 200ms var(--ease), opacity 200ms var(--ease);
}
.chat-fab:hover { transform: scale(1.05); }
.chat-fab.is-hidden { opacity: 0; pointer-events: none; transform: scale(0.9); }

.chat-panel {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: 100%;
  max-width: 420px;
  background: rgba(255, 255, 255, 0.85);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border-left: 1px solid var(--hairline);
  display: flex;
  flex-direction: column;
  z-index: 30;
  transform: translateX(100%);
  transition: transform 400ms var(--ease);
}
.chat-panel.is-open { transform: translateX(0); }

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  padding: 1.5rem;
  border-bottom: 1px solid var(--hairline);
}
.chat-title {
  margin: 0;
  font-size: 1.5rem;
  line-height: 1.1;
  color: var(--foreground);
}
.chat-sub {
  margin: 0.25rem 0 0;
  font-size: 0.875rem;
  color: var(--muted);
}
.chat-close {
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--foreground);
  flex-shrink: 0;
  transition: background 180ms var(--ease);
}
.chat-close:hover { background: rgba(0, 0, 0, 0.05); }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  scrollbar-width: thin;
  scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}
.chat-messages::-webkit-scrollbar { width: 6px; }
.chat-messages::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.15); border-radius: 3px; }
.chat-messages::-webkit-scrollbar-track { background: transparent; }

.chat-msg {
  max-width: 80%;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  line-height: 1.5;
  border-radius: 1rem;
  white-space: pre-wrap;
  word-break: break-word;
  animation: chat-bubble-in 260ms var(--ease) both;
  transform-origin: bottom left;
  will-change: transform, opacity;
}
.chat-msg--assistant {
  align-self: flex-start;
  background: var(--soft);
  color: var(--foreground);
  border-bottom-left-radius: 0.25rem;
}
.chat-msg--user {
  align-self: flex-end;
  background: var(--foreground);
  color: #FFFFFF;
  border-bottom-right-radius: 0.25rem;
  transform-origin: bottom right;
}
@keyframes chat-bubble-in {
  from { opacity: 0; transform: translateY(6px) scale(0.97); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}
.chat-msg-link {
  color: var(--foreground);
  text-decoration: underline;
  text-underline-offset: 2px;
}
.chat-msg-link:hover { text-decoration-thickness: 2px; }

.chat-typing {
  align-self: flex-start;
  background: var(--soft);
  padding: 0.75rem 1rem;
  border-radius: 1rem;
  border-bottom-left-radius: 0.25rem;
  animation: chat-bubble-in 260ms var(--ease) both;
  transform-origin: bottom left;
  will-change: transform, opacity;
}
.chat-typing span {
  display: inline-block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--foreground);
  margin: 0 2px;
  animation: dot-bounce 1.2s ease-in-out infinite;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes dot-bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-6px); opacity: 1; }
}

.chat-input {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 1rem;
  border-top: 1px solid var(--hairline);
}
.chat-field {
  flex: 1;
  background: var(--soft);
  border: 0;
  border-radius: 9999px;
  padding: 0.625rem 1rem;
  font-family: var(--font-body);
  font-size: 0.875rem;
  color: var(--foreground);
}
.chat-field:focus { outline: none; box-shadow: 0 0 0 2px var(--foreground); }
.chat-send {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 9999px;
  background: var(--foreground);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: opacity 180ms var(--ease);
}
.chat-send:disabled { opacity: 0.4; cursor: not-allowed; }

@media (max-width: 767px) {
  .chat-panel {
    max-width: 100%;
    border-left: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  .chat-panel { transition: none; }
  .chat-msg,
  .chat-typing { animation: none; }
}
