/* ── Feoda Chat Widget ─────────────────────────────────────────────── */

#feoda-chat {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 9999;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

/* Toggle button */
#feoda-chat-toggle {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: #6200ea;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 16px rgba(98, 0, 234, 0.4);
  transition: background 0.2s, transform 0.2s;
}

#feoda-chat-toggle:hover {
  background: #7c3aed;
  transform: scale(1.05);
}

#feoda-chat-toggle.feoda-chat-toggle--active {
  background: #4a00b4;
}

/* Panel */
#feoda-chat-panel {
  position: absolute;
  bottom: 64px;
  right: 0;
  width: 360px;
  max-height: 520px;
  background: var(--md-default-bg-color, #fff);
  border: 1px solid rgba(0,0,0,0.12);
  border-radius: 12px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.18);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
#feoda-chat-header {
  background: #6200ea;
  color: #fff;
  padding: 0.75rem 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.01em;
}

#feoda-chat-close {
  background: none;
  border: none;
  color: #fff;
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  padding: 0 0.2rem;
  opacity: 0.8;
  transition: opacity 0.15s;
}

#feoda-chat-close:hover { opacity: 1; }

/* Messages */
#feoda-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  font-size: 0.875rem;
  line-height: 1.5;
}

.feoda-msg {
  max-width: 88%;
  padding: 0.6rem 0.85rem;
  border-radius: 10px;
  word-break: break-word;
}

.feoda-msg--user {
  background: #6200ea;
  color: #fff;
  align-self: flex-end;
  border-bottom-right-radius: 3px;
}

.feoda-msg--assistant {
  background: var(--md-code-bg-color, #f5f5f5);
  color: var(--md-default-fg-color, #1a1a1a);
  align-self: flex-start;
  border-bottom-left-radius: 3px;
}

.feoda-msg--assistant code {
  background: rgba(98,0,234,0.1);
  padding: 0.1em 0.35em;
  border-radius: 3px;
  font-size: 0.85em;
}

.feoda-msg-sources {
  font-size: 0.72rem;
  color: var(--md-default-fg-color--light, #666);
  padding: 0.2rem 0.25rem;
  align-self: flex-start;
  max-width: 88%;
}

.feoda-msg-sources summary {
  cursor: pointer;
  opacity: 0.7;
  font-weight: 500;
  user-select: none;
  transition: opacity 0.15s;
}

.feoda-msg-sources summary:hover {
  opacity: 1;
}

.feoda-sources-list {
  list-style: none;
  padding: 0.3rem 0 0 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}

.feoda-sources-list a {
  color: #6200ea;
  text-decoration: none;
  word-break: break-all;
  transition: color 0.15s;
}

.feoda-sources-list a:hover {
  color: #7c3aed;
  text-decoration: underline;
}

[data-md-color-scheme="slate"] .feoda-sources-list a {
  color: #b388ff;
}

[data-md-color-scheme="slate"] .feoda-sources-list a:hover {
  color: #d1c4e9;
}

.feoda-error { color: #c62828; }

/* Input area */
#feoda-chat-input-area {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem;
  border-top: 1px solid rgba(0,0,0,0.08);
  background: var(--md-default-bg-color, #fff);
}

#feoda-chat-input {
  flex: 1;
  border: 1px solid rgba(0,0,0,0.2);
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  font-size: 0.875rem;
  resize: none;
  background: var(--md-default-bg-color, #fff);
  color: var(--md-default-fg-color, #1a1a1a);
  outline: none;
  transition: border-color 0.15s;
  font-family: inherit;
}

#feoda-chat-input:focus {
  border-color: #6200ea;
}

#feoda-chat-input:disabled {
  opacity: 0.5;
}

#feoda-chat-send {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: none;
  background: #6200ea;
  color: #fff;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  align-self: flex-end;
  transition: background 0.15s;
}

#feoda-chat-send:hover { background: #7c3aed; }
#feoda-chat-send:disabled { opacity: 0.5; cursor: not-allowed; }

#feoda-chat-send.feoda-loading::after {
  content: '';
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: feoda-spin 0.7s linear infinite;
  display: block;
}

#feoda-chat-send.feoda-loading svg { display: none; }

@keyframes feoda-spin {
  to { transform: rotate(360deg); }
}

/* Dark mode */
[data-md-color-scheme="slate"] #feoda-chat-panel {
  border-color: rgba(255,255,255,0.1);
}

[data-md-color-scheme="slate"] #feoda-chat-input {
  border-color: rgba(255,255,255,0.2);
}

/* Mobile responsive */
@media (max-width: 480px) {
  #feoda-chat-panel {
    width: calc(100vw - 2rem);
    right: 0;
  }
  #feoda-chat {
    bottom: 1rem;
    right: 1rem;
  }
}
