/* =============================================================================
   SwarDB Chat Widget
   Floating assistant button + slide-up chat panel
   ============================================================================= */

/* ── Floating button ────────────────────────────────────────────────────────── */
#chat-fab {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--color-primary);
  color: #FFF8F0;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(139,26,26,.4);
  z-index: 900;
  transition: background .2s, transform .15s;
}
#chat-fab:hover { background: var(--color-primary-lt); transform: scale(1.07); }
#chat-fab svg   { pointer-events: none; }

/* ── Chat panel ─────────────────────────────────────────────────────────────── */
#chat-panel {
  position: fixed;
  bottom: 5rem;
  right: 1.5rem;
  width: 340px;
  max-width: calc(100vw - 2rem);
  height: 480px;
  max-height: calc(100vh - 7rem);
  background: var(--color-bg-card);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  z-index: 901;
  overflow: hidden;
  transform: scale(.95) translateY(8px);
  opacity: 0;
  pointer-events: none;
  transition: transform .2s ease, opacity .2s ease;
}
#chat-panel.open {
  transform: scale(1) translateY(0);
  opacity: 1;
  pointer-events: all;
}

/* ── Header ─────────────────────────────────────────────────────────────────── */
#chat-header {
  background: var(--color-primary);
  color: #FFF8F0;
  padding: .75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
#chat-header h3 {
  margin: 0;
  font-size: .95rem;
  font-weight: 600;
  color: #FFF8F0;
}
#chat-header p {
  font-size: .72rem;
  opacity: .8;
  margin: .1rem 0 0;
}
#chat-close {
  background: none;
  border: none;
  color: #FFF8F0;
  cursor: pointer;
  padding: .25rem;
  opacity: .8;
  line-height: 1;
  font-size: 1.1rem;
}
#chat-close:hover { opacity: 1; }

/* ── Messages ───────────────────────────────────────────────────────────────── */
#chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: .75rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
  scroll-behavior: smooth;
}
.chat-msg {
  max-width: 88%;
  padding: .5rem .75rem;
  border-radius: var(--radius-lg);
  font-size: .88rem;
  line-height: 1.5;
  word-break: break-word;
}
.chat-msg.user {
  background: var(--color-primary);
  color: #FFF8F0;
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}
.chat-msg.assistant {
  background: var(--color-bg-muted);
  color: var(--color-text);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}
.chat-msg.assistant ul {
  margin: .4rem 0 0 1rem;
  padding: 0;
}
.chat-msg.assistant li { margin: .15rem 0; }

/* Typing indicator */
.chat-typing {
  align-self: flex-start;
  display: flex;
  gap: 4px;
  padding: .5rem .75rem;
  background: var(--color-bg-muted);
  border-radius: var(--radius-lg);
  border-bottom-left-radius: 3px;
}
.chat-typing span {
  width: 7px;
  height: 7px;
  background: var(--color-text-muted);
  border-radius: 50%;
  animation: chat-bounce .9s infinite ease-in-out;
}
.chat-typing span:nth-child(2) { animation-delay: .15s; }
.chat-typing span:nth-child(3) { animation-delay: .3s;  }
@keyframes chat-bounce {
  0%, 80%, 100% { transform: scale(.7); opacity: .5; }
  40%            { transform: scale(1);  opacity: 1;  }
}

/* ── Input area ─────────────────────────────────────────────────────────────── */
#chat-input-row {
  display: flex;
  border-top: 1px solid var(--color-border);
  flex-shrink: 0;
}
#chat-input {
  flex: 1;
  border: none;
  padding: .65rem .75rem;
  font-size: .88rem;
  font-family: inherit;
  background: var(--color-bg-card);
  color: var(--color-text);
  resize: none;
  outline: none;
  min-height: 42px;
  max-height: 100px;
}
#chat-send {
  background: var(--color-primary);
  color: #FFF8F0;
  border: none;
  padding: 0 .9rem;
  cursor: pointer;
  font-size: .9rem;
  transition: background .2s;
}
#chat-send:hover    { background: var(--color-primary-lt); }
#chat-send:disabled { background: var(--color-border); cursor: default; }

/* ── Mobile ─────────────────────────────────────────────────────────────────── */
@media (max-width: 480px) {
  #chat-panel {
    right: .5rem;
    left: .5rem;
    width: auto;
    bottom: 4.5rem;
  }
  #chat-fab { bottom: 1rem; right: 1rem; }
}
