/* ═══════════════════════════════════════
   AI Chat Widget
   ═══════════════════════════════════════ */

#ai-chat-wrapper {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 3;
  font-family: "Noto Sans SC", sans-serif;
}

/* When chat is open, raise above everything */
#ai-chat-wrapper:has(#ai-chat-panel.open) {
  z-index: 9999;
}

#ai-chat-btn {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  border: none;
  background: var(--wiki-accent, #3f51b5);
  color: white;
  cursor: pointer;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.2s, box-shadow 0.2s;
}

#ai-chat-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.28);
}

#ai-chat-btn.hidden {
  display: none;
}

#ai-chat-panel {
  display: none;
  flex-direction: column;
  width: 360px;
  max-width: calc(100vw - 2rem);
  height: 480px;
  max-height: calc(100vh - 6rem);
  border-radius: 16px;
  background: var(--wiki-card-bg, #fff);
  border: 1px solid var(--wiki-card-border, #e0e0e0);
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  overflow: hidden;
}

#ai-chat-panel.open {
  display: flex;
}

#ai-chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: var(--wiki-accent, #3f51b5);
  color: white;
  font-size: 0.88rem;
  font-weight: 600;
}

#ai-chat-close {
  background: none;
  border: none;
  color: white;
  font-size: 1.3rem;
  cursor: pointer;
  line-height: 1;
  opacity: 0.8;
}

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

#ai-chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.ai-chat-msg {
  max-width: 85%;
  padding: 0.55rem 0.85rem;
  border-radius: 12px;
  font-size: 0.82rem;
  line-height: 1.6;
  word-break: break-word;
}

.ai-chat-user {
  align-self: flex-end;
  background: var(--wiki-accent, #3f51b5);
  color: white;
  border-bottom-right-radius: 4px;
}

.ai-chat-assistant {
  align-self: flex-start;
  background: var(--wiki-accent-soft, #eef1fb);
  color: inherit;
  border-bottom-left-radius: 4px;
}

[data-md-color-scheme="slate"] .ai-chat-assistant {
  background: var(--wiki-prompt-bg, #242838);
}

#ai-chat-input-row {
  display: flex;
  gap: 0.4rem;
  padding: 0.6rem 0.75rem;
  border-top: 1px solid var(--wiki-card-border, #e0e0e0);
}

#ai-chat-input {
  flex: 1;
  border: 1px solid var(--wiki-card-border, #e0e0e0);
  border-radius: 8px;
  padding: 0.45rem 0.7rem;
  font-size: 0.82rem;
  background: transparent;
  color: inherit;
  outline: none;
}

#ai-chat-input:focus {
  border-color: var(--wiki-accent, #3f51b5);
}

#ai-chat-send {
  border: none;
  border-radius: 8px;
  background: var(--wiki-accent, #3f51b5);
  color: white;
  padding: 0.45rem 0.85rem;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

#ai-chat-send:hover {
  opacity: 0.9;
}

@media screen and (max-width: 45em) {
  #ai-chat-panel {
    width: calc(100vw - 2rem);
    height: calc(100vh - 8rem);
    bottom: 0;
    right: 0;
    border-radius: 16px 16px 0 0;
  }

  #ai-chat-wrapper {
    bottom: 1rem;
    right: 1rem;
  }
}
