.chat-widget {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 90;
  font-family: var(--sans);
}

.chat-bubble {
  position: relative;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: linear-gradient(135deg, #25d366, #12a150);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: 0 14px 30px -8px rgba(18, 161, 80, 0.6);
  transition: transform 0.2s ease, box-shadow 0.2s ease;
}
.chat-bubble::before {
  content: ""; position: absolute; inset: 0; border-radius: 50%;
  border: 3px solid #25d366; animation: chat-pulse 2s ease-out infinite; pointer-events: none;
}
.chat-widget.is-open .chat-bubble::before { animation: none; opacity: 0; }
@keyframes chat-pulse {
  0% { transform: scale(1); opacity: 0.7; }
  100% { transform: scale(1.55); opacity: 0; }
}
.chat-bubble:hover { transform: translateY(-3px); box-shadow: 0 20px 40px -10px rgba(18, 161, 80, 0.7); }
.chat-bubble svg { width: 30px; height: 30px; }
.chat-bubble .chat-bubble-icon-close { display: none; }
.chat-widget.is-open .chat-bubble-icon-chat { display: none; }
.chat-widget.is-open .chat-bubble-icon-close { display: block; }

.chat-bubble-dot {
  position: absolute; top: 2px; right: 2px; width: 12px; height: 12px; border-radius: 50%;
  background: #ff4d4d; border: 2px solid #fff;
}

.chat-panel {
  position: absolute;
  right: 0;
  bottom: 74px;
  width: min(360px, calc(100vw - 2.5rem));
  height: min(520px, calc(100vh - 8rem));
  background: #fff;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  opacity: 0;
  transform: translateY(16px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.chat-widget.is-open .chat-panel {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}

.chat-panel-header {
  background: var(--navy);
  color: #fff;
  padding: 1rem 1.1rem;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  flex-shrink: 0;
}
.chat-panel-avatar {
  width: 34px; height: 34px; border-radius: 50%; background: rgba(255,255,255,0.12);
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.chat-panel-avatar svg { width: 18px; height: 18px; }
.chat-panel-title { font-family: var(--serif); font-weight: 600; font-size: 0.98rem; line-height: 1.2; }
.chat-panel-subtitle { font-size: 0.76rem; color: #cfd9ef; display: flex; align-items: center; gap: 0.4em; }
.chat-panel-subtitle .pulse-dot { width: 7px; height: 7px; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  background: var(--paper);
}

.chat-msg {
  max-width: 84%;
  padding: 0.6em 0.85em;
  border-radius: 14px;
  font-size: 0.88rem;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat-msg-bot {
  align-self: flex-start;
  background: #fff;
  border: 1px solid var(--border);
  color: var(--ink);
  border-bottom-left-radius: 4px;
}
.chat-msg-user {
  align-self: flex-end;
  background: var(--navy);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-msg-error {
  align-self: flex-start;
  background: #fdeceb;
  border: 1px solid #f6c9c4;
  color: #a3372b;
  border-bottom-left-radius: 4px;
}

.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: 0.7em 0.9em;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 14px;
  border-bottom-left-radius: 4px;
}
.chat-typing span {
  width: 6px; height: 6px; border-radius: 50%; background: #b7c0d4;
  animation: chatTypingBounce 1.2s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: 0.15s; }
.chat-typing span:nth-child(3) { animation-delay: 0.3s; }
@keyframes chatTypingBounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-4px); opacity: 1; }
}

.chat-input-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid var(--border);
  background: #fff;
  flex-shrink: 0;
}
.chat-input {
  flex: 1;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.6em 0.8em;
  font-family: var(--sans);
  font-size: 0.88rem;
  color: var(--ink);
  background: var(--paper);
  max-height: 90px;
  line-height: 1.4;
}
.chat-input:focus {
  outline: none; border-color: var(--blue-glow); box-shadow: 0 0 0 3px rgba(76,124,243,0.18); background: #fff;
}
.chat-send {
  width: 38px; height: 38px; border-radius: 10px; border: none; background: #12a150; color: #fff;
  display: flex; align-items: center; justify-content: center; cursor: pointer; flex-shrink: 0;
  transition: background 0.2s ease, opacity 0.2s ease;
}
.chat-send:hover { background: #0e8a43; }
.chat-send:disabled { opacity: 0.5; cursor: default; }
.chat-send svg { width: 17px; height: 17px; }

@media (prefers-reduced-motion: reduce) {
  .chat-bubble::before { animation: none; opacity: 0; }
  .chat-typing span { animation: none; opacity: 0.8; }
}

@media (max-width: 480px) {
  .chat-widget { right: 0.75rem; bottom: 0.75rem; }
  .chat-panel { width: calc(100vw - 1.5rem); height: min(70vh, 560px); bottom: 72px; }
}
