/* 本草纲目 chat widget · 古籍风 */

.bcgm-chat {
  display: flex;
  flex-direction: column;
  background: rgba(255, 252, 240, 0.6);
  border: 1px solid var(--rule);
  border-radius: 4px;
  box-shadow: 0 2px 8px var(--shadow);
  font-family: var(--ff-serif);
  color: var(--ink);
  overflow: hidden;
}

.bcgm-chat[data-variant="home"] {
  max-width: 720px;
  margin: 0 auto;
  height: 320px;
}

.bcgm-chat[data-variant="home"] .bcgm-chat-body {
  min-height: 0;
}

.bcgm-chat[data-variant="detail"] {
  height: 100%;
  min-height: 0;
}

.chat-rail > [data-chat-mount] {
  height: 100%;
  min-height: 0;
  display: flex;
}

.chat-rail > [data-chat-mount] > .bcgm-chat {
  flex: 1;
  min-height: 0;
}

.bcgm-chat-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--rule);
  background: linear-gradient(to bottom, var(--paper) 0%, var(--paper-deep) 100%);
}

.bcgm-chat-title {
  font-size: 0.95rem;
  letter-spacing: 0.1em;
  color: var(--accent);
  font-weight: 600;
}

.bcgm-chat-clear {
  font-size: 0.78rem;
  padding: 3px 10px;
  background: transparent;
  border: 1px solid var(--rule);
  color: var(--ink-soft);
  border-radius: 3px;
  cursor: pointer;
  font-family: var(--ff-sans);
}

.bcgm-chat-clear:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.bcgm-chat-body {
  flex: 1;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-height: 0;
}

.bcgm-chat[data-variant="detail"] .bcgm-chat-body {
  min-height: 0;
}

.bcgm-placeholder {
  color: var(--ink-soft);
  font-size: 0.9rem;
  line-height: 1.8;
}

.bcgm-placeholder ul {
  margin: 8px 0 0;
  padding-left: 20px;
}

.bcgm-placeholder li {
  margin: 4px 0;
  cursor: pointer;
  color: var(--accent-soft);
}

.bcgm-placeholder li:hover {
  color: var(--accent);
  text-decoration: underline;
}

.bcgm-msg {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.bcgm-msg-user .bcgm-bubble {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-radius: 10px 10px 2px 10px;
  max-width: 85%;
}

.bcgm-msg-assistant .bcgm-bubble {
  align-self: flex-start;
  background: var(--paper-deep);
  color: var(--ink);
  border-radius: 10px 10px 10px 2px;
  max-width: 92%;
  border-left: 3px solid var(--moss);
}

.bcgm-bubble {
  padding: 10px 14px;
  font-size: 0.94rem;
  line-height: 1.75;
  white-space: pre-wrap;
  word-break: break-word;
}

.bcgm-bubble strong { font-weight: 600; }

.bcgm-cite {
  display: inline-block;
  font-family: var(--ff-sans);
  font-size: 0.7rem;
  background: var(--gold);
  color: #fff;
  padding: 1px 6px;
  margin: 0 2px;
  border-radius: 8px;
  text-decoration: none;
  vertical-align: super;
  line-height: 1.4;
}

.bcgm-cite:hover {
  background: var(--accent);
}

.bcgm-retrieved {
  margin-top: 6px;
  font-size: 0.8rem;
  font-family: var(--ff-sans);
  line-height: 1.4;
  white-space: normal;
}

.bcgm-retrieved * { white-space: normal; }

.bcgm-retrieved summary {
  cursor: pointer;
  color: var(--ink-soft);
  padding: 2px 0;
  user-select: none;
}

.bcgm-retrieved summary:hover { color: var(--accent); }

.bcgm-retrieved ul {
  margin: 2px 0 0;
  padding-left: 16px;
  list-style: none;
}

.bcgm-retrieved li {
  margin: 0;
  padding: 1px 0;
  line-height: 1.4;
}

.bcgm-retrieved a {
  color: var(--accent-soft);
  text-decoration: none;
}

.bcgm-retrieved a:hover {
  color: var(--accent);
  text-decoration: underline;
}

.bcgm-retrieved .ref-meta {
  color: var(--ink-soft);
  margin-left: 6px;
  font-size: 0.78rem;
}

.bcgm-loading {
  align-self: flex-start;
  color: var(--ink-soft);
  font-size: 0.88rem;
  font-style: italic;
  padding: 6px 10px;
}

.bcgm-loading::after {
  content: '...';
  animation: bcgm-dots 1.2s steps(3, end) infinite;
}

@keyframes bcgm-dots {
  0% { content: ''; }
  33% { content: '.'; }
  66% { content: '..'; }
  100% { content: '...'; }
}

.bcgm-error {
  align-self: stretch;
  color: var(--accent);
  background: rgba(122, 59, 28, 0.08);
  border: 1px solid var(--accent-soft);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 0.88rem;
  font-family: var(--ff-sans);
}

.bcgm-chat-input-row {
  border-top: 1px solid var(--rule);
  padding: 10px 12px;
  display: flex;
  gap: 8px;
  background: var(--paper);
}

.bcgm-chat-input {
  flex: 1;
  min-width: 0;
  resize: none;
  border: 1px solid var(--rule);
  border-radius: 4px;
  padding: 8px 10px;
  font-family: var(--ff-serif);
  font-size: 0.82rem;
  color: var(--ink);
  background: #fff;
  line-height: 1.5;
  max-height: 120px;
  min-height: 40px;
  outline: none;
}

.bcgm-chat-input::placeholder { font-size: 0.82rem; }

.bcgm-chat-input:focus {
  border-color: var(--accent-soft);
}

.bcgm-chat-send {
  padding: 0 14px;
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 4px;
  font-family: var(--ff-serif);
  font-size: 0.85rem;
  cursor: pointer;
  letter-spacing: 0.05em;
  white-space: nowrap;
  flex-shrink: 0;
}

.bcgm-chat-send:hover:not(:disabled) {
  background: var(--accent-soft);
}

.bcgm-chat-send:disabled {
  background: var(--rule);
  cursor: not-allowed;
}
