/* ============================================================
   FAB
   ============================================================ */
.chat-fab {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 20px 12px 16px;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: var(--accent-inv);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, .18), 0 1px 4px rgba(0, 0, 0, .08);
  transition: transform .15s cubic-bezier(.34, 1.56, .64, 1), box-shadow .15s;
}

.chat-fab:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, .22);
}

.chat-fab:active {
  transform: scale(.97);
}

/* ============================================================
   WIDGET
   ============================================================ */
.chat-widget {
  position: fixed;
  bottom: 80px;
  right: 24px;
  z-index: 999;
  width: 360px;
  height: 640px;
  display: flex;
  flex-direction: column;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: var(--surface);
  box-shadow: 0 8px 32px rgba(0, 0, 0, .12), 0 2px 8px rgba(0, 0, 0, .06);
  overflow: hidden;
  transform: scale(.9) translateY(16px);
  opacity: 0;
  pointer-events: none;
  transform-origin: bottom right;
  transition: transform .24s cubic-bezier(.34, 1.56, .64, 1), opacity .18s ease;
}

body[data-theme="dark"] .chat-widget {
  box-shadow: 0 8px 32px rgba(0, 0, 0, .5), 0 2px 8px rgba(0, 0, 0, .3);
}

.chat-widget.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.chat-avatar {
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-inv);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}

.chat-name {
  font-weight: 700;
  font-size: 13.5px;
  color: var(--text);
  line-height: 1.3;
}

.chat-status {
  display: inline-flex;
  align-items: center;
  margin-top: 3px;
  font-size: 11px;
  font-weight: 600;
  color: #15803d;
  background: #dcfce7;
  padding: 1px 7px;
  border-radius: 999px;
  letter-spacing: .1px;
  width: fit-content;
}

body[data-theme="dark"] .chat-status {
  color: #4ade80;
  background: rgba(74, 222, 128, .12);
}

.chat-close {
  width: 30px;
  height: 30px;
  background: none;
  border: none;
  border-radius: 50%;
  color: var(--muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s, color .15s;
  flex-shrink: 0;
}

.chat-close:hover {
  background: var(--bg-2);
  color: var(--text);
}

/* ── Messages area ── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 14px 14px 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  scroll-behavior: smooth;
  background: var(--bg);
}

.chat-messages::-webkit-scrollbar {
  width: 3px;
}

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

/* Message group spacing */
.chat-msg {
  display: flex;
  flex-direction: column;
  max-width: 80%;
  margin-bottom: 2px;
}

.chat-msg.bot {
  align-self: flex-start;
}

.chat-msg.user {
  align-self: flex-end;
  align-items: flex-end;
}

/* Extra top margin when sender changes */
.chat-msg.bot+.chat-msg.user,
.chat-msg.user+.chat-msg.bot {
  margin-top: 8px;
}

.chat-bubble {
  padding: 9px 13px;
  border-radius: 18px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}

.chat-bubble a {
  text-decoration: underline;
}

.chat-msg.bot .chat-bubble {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.chat-msg.user .chat-bubble {
  background: var(--accent);
  color: var(--accent-inv);
  border-bottom-right-radius: 4px;
}

.chat-time {
  font-size: 10.5px;
  color: var(--muted-2);
  margin-top: 3px;
  padding: 0 2px;
  align-self: flex-start;
}

.chat-msg.user .chat-time {
  align-self: flex-end;
}

/* ── Quick replies ── */
.chat-quick {
  flex-shrink: 0;
  padding: 8px 14px 10px;
  background: var(--bg);
  border-top: 1px solid var(--border-2, var(--border));
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chat-suggestion {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  padding: 5px 11px;
  border-radius: 999px;
  cursor: pointer;
  white-space: nowrap;
  transition: background .12s, border-color .12s, color .12s, transform .12s var(--ease, cubic-bezier(.22, 1, .36, 1));
}

.chat-suggestion:hover {
  background: var(--bg-2);
  border-color: var(--text-2);
  color: var(--text);
  transform: translateY(-1px);
}

.chat-suggestion:active {
  transform: scale(.96);
}

/* ── Typing ── */
.chat-typing .chat-bubble {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 11px 14px;
}

.chat-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--muted);
  animation: chatBounce 1.2s ease infinite;
}

.chat-dot:nth-child(2) {
  animation-delay: .18s;
}

.chat-dot:nth-child(3) {
  animation-delay: .36s;
}

@keyframes chatBounce {

  0%,
  80%,
  100% {
    transform: translateY(0);
    opacity: .3;
  }

  40% {
    transform: translateY(-5px);
    opacity: 1;
  }
}

/* ── Input ── */
.chat-input-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px 10px;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-family: inherit;
  font-size: 13.5px;
  background: var(--bg-2);
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}

.chat-input::placeholder {
  color: var(--muted-2);
}

.chat-input:focus {
  border-color: var(--text-2);
}

.chat-send {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  border: none;
  background: var(--accent);
  color: var(--accent-inv);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity .15s, transform .15s var(--ease, cubic-bezier(.22, 1, .36, 1));
}

.chat-send:hover {
  opacity: .82;
  transform: scale(1.08);
}

.chat-send:active {
  transform: scale(.93);
}

/* ── Mobile ── */
@media (max-width: 480px) {
  .chat-widget {
    width: calc(100vw - 16px);
    height: 72vh;
    right: 8px;
    bottom: 72px;
    border-radius: 14px;
  }

  .chat-fab-label {
    display: none;
  }

  .chat-fab {
    padding: 14px;
    border-radius: 50%;
    right: 16px;
    bottom: 16px;
  }
}