/* ===== Chat Widget ===== */
.chat-widget {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 9999;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
}

/* Toggle button */
.chat-toggle {
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 14px rgba(37,99,235,.4);
  transition: transform .2s, background .2s;
}
.chat-toggle:hover { background: #1d4ed8; transform: scale(1.05); }
.chat-toggle .icon-chat { display: block; width: 24px; height: 24px; }
.chat-toggle .icon-close { display: none; width: 24px; height: 24px; }
.chat-widget.open .chat-toggle .icon-chat { display: none; }
.chat-widget.open .chat-toggle .icon-close { display: block; }

/* Window */
.chat-window {
  position: absolute;
  right: 0;
  bottom: 72px;
  width: 20vw;
  max-width: 420px;
  min-width: 300px;
  height: 50vh;
  max-height: 600px;
  min-height: 350px;
  background: #fff;
  border-radius: 12px;
  box-shadow: 0 10px 40px rgba(0,0,0,.15);
  display: none;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid #e5e7eb;
}
.chat-widget.open .chat-window { display: flex; animation: slideUp .2s ease; }
@keyframes slideUp { from {opacity:0; transform:translateY(10px);} to {opacity:1; transform:none;} }

.chat-header {
  padding: 12px 16px;
  background: #f9fafb;
  border-bottom: 1px solid #e5e7eb;
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 600;
  font-size: 14px;
  color: #111827;
}
.chat-close {
  background: none;
  border: none;
  font-size: 20px;
  line-height: 1;
  cursor: pointer;
  color: #6b7280;
}
.chat-close:hover { color: #111827; }

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.msg {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  white-space: pre-wrap;
  word-wrap: break-word;
  animation: fadeIn .2s ease;
}
@keyframes fadeIn { from {opacity:0; transform:translateY(4px);} to {opacity:1; transform:none;} }
.msg.user {
  align-self: flex-end;
  background: #2563eb;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.assistant {
  align-self: flex-start;
  background: #f3f4f6;
  color: #111827;
  border-bottom-left-radius: 4px;
}
.msg .meta { font-size: 11px; opacity: .7; margin-top: 4px; text-align: right; }
.msg.assistant .meta { text-align: left; }

/* Typing indicator */
.typing { display:inline-flex; gap:3px; padding:4px 0; }
.typing span { width:6px; height:6px; background:#9ca3af; border-radius:50%; animation:bounce 1.2s infinite ease-in-out; }
.typing span:nth-child(2){animation-delay:.2s}
.typing span:nth-child(3){animation-delay:.4s}
@keyframes bounce {0%,80%,100%{transform:scale(0)}40%{transform:scale(1)}}

/* Form */
.chat-form { padding: 12px; border-top: 1px solid #e5e7eb; background: #fff; }
.input-wrap { display:flex; gap:8px; }
#chat-input {
  flex:1;
  min-height: 44px;
  max-height: 140px;
  padding: 10px 12px;
  border: 1px solid #d1d5db;
  border-radius: 8px;
  resize: none;
  font: inherit;
  font-size: 14px;
  line-height: 1.5;
  outline: none;
}
#chat-input:focus { border-color: #2563eb; box-shadow: 0 0 0 3px rgba(37,99,235,.15); }
.chat-send {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: #2563eb;
  color: #fff;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background .2s;
}
.chat-send:hover { background: #1d4ed8; }
.chat-send svg { width: 20px; height: 20px; }
.chat-send:disabled { opacity: .5; cursor: not-allowed; }

/* Mobile adjustments */
@media (max-width: 640px) {
  .chat-window { width: calc(100vw - 32px); right: -16px; bottom: 72px; height: 70vh; max-height: none; }
  .chat-widget { right: 16px; bottom: 16px; }
}
