/*
 * ct package website assistant widget styles.
 * pkgdown automatically links pkgdown/extra.css on every page.
 *
 * Colours are driven by CSS variables that follow pkgdown's Bootstrap 5
 * light/dark switch (data-bs-theme="dark").
 */

#ct-ai {
  --ct-ai-accent: #D9C9BA;
  --ct-ai-accent-fg: #ffffff;
  --ct-ai-bg: #ffffff;
  --ct-ai-fg: #1f2328;
  --ct-ai-muted: #6a737d;
  --ct-ai-border: #e1e4e8;
  --ct-ai-user-bg: #D9C9BA;
  --ct-ai-user-fg: #ffffff;
  --ct-ai-code-bg: #f4f1ea;
}

[data-bs-theme="dark"] #ct-ai {
  --ct-ai-bg: #1c1f24;
  --ct-ai-fg: #e6edf3;
  --ct-ai-muted: #9aa4ae;
  --ct-ai-border: #30363d;
  --ct-ai-code-bg: #2a2f37;
}

/* Toggle button */
#ct-ai-toggle {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 1050;
  border: none;
  border-radius: 999px;
  padding: 12px 18px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  color: var(--ct-ai-accent-fg);
  background: var(--ct-ai-accent);
  box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
#ct-ai-toggle:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.3);
}

/* Dimmed backdrop behind the modal */
#ct-ai-backdrop {
  position: fixed;
  inset: 0;
  z-index: 1055;
  background: rgba(0, 0, 0, 0.45);
}

/* Panel — centered modal */
#ct-ai-panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 1060;
  display: flex;
  flex-direction: column;
  width: min(680px, 94vw);
  height: min(78vh, 760px);
  background: var(--ct-ai-bg);
  color: var(--ct-ai-fg);
  border: 1px solid var(--ct-ai-border);
  border-radius: 14px;
  box-shadow: 0 18px 60px rgba(0, 0, 0, 0.4);
  overflow: hidden;
}
/* Expanded — near-fullscreen */
#ct-ai-panel.ct-ai-expanded {
  width: 96vw;
  height: 94vh;
}

#ct-ai-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-weight: 600;
  color: var(--ct-ai-accent-fg);
  background: var(--ct-ai-accent);
}
#ct-ai-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
#ct-ai-expand,
#ct-ai-close {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: transparent;
  color: var(--ct-ai-accent-fg);
  cursor: pointer;
  padding: 5px;
  border-radius: 6px;
  opacity: 0.9;
}
#ct-ai-expand:hover,
#ct-ai-close:hover {
  opacity: 1;
  background: rgba(255, 255, 255, 0.18);
}

/* Message log */
#ct-ai-log {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.ct-ai-msg {
  display: flex;
}
.ct-ai-msg.ct-ai-u {
  justify-content: flex-end;
}
.ct-ai-bubble {
  max-width: 85%;
  padding: 9px 13px;
  border-radius: 12px;
  font-size: 0.9rem;
  line-height: 1.45;
  word-wrap: break-word;
}
.ct-ai-a .ct-ai-bubble {
  background: var(--ct-ai-code-bg);
  color: var(--ct-ai-fg);
  border-bottom-left-radius: 3px;
}
.ct-ai-u .ct-ai-bubble {
  background: var(--ct-ai-user-bg);
  color: var(--ct-ai-user-fg);
  border-bottom-right-radius: 3px;
}
.ct-ai-typing {
  color: var(--ct-ai-muted);
}

/* Animated "typing" dots shown while the model is responding */
.ct-ai-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 2px 0;
}
.ct-ai-dots span {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ct-ai-muted);
  opacity: 0.4;
  animation: ct-ai-blink 1.2s infinite ease-in-out both;
}
.ct-ai-dots span:nth-child(2) { animation-delay: 0.2s; }
.ct-ai-dots span:nth-child(3) { animation-delay: 0.4s; }
@keyframes ct-ai-blink {
  0%, 80%, 100% { opacity: 0.25; transform: translateY(0); }
  40% { opacity: 1; transform: translateY(-3px); }
}

/* Rendered markdown inside answers */
.ct-ai-bubble p { margin: 0 0 0.5em; }
.ct-ai-bubble p:last-child { margin-bottom: 0; }
.ct-ai-bubble ul { margin: 0.3em 0 0.5em; padding-left: 1.2em; }
.ct-ai-bubble h3, .ct-ai-bubble h4, .ct-ai-bubble h5, .ct-ai-bubble h6 {
  margin: 0.5em 0 0.3em;
  font-size: 0.95rem;
}
.ct-ai-bubble code {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82em;
  background: rgba(127, 127, 127, 0.18);
  padding: 1px 5px;
  border-radius: 4px;
}
.ct-ai-bubble pre {
  background: #0d1117;
  color: #e6edf3;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 0.5em 0;
}
.ct-ai-bubble pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: 0.82em;
}
.ct-ai-bubble a { color: var(--ct-ai-accent); text-decoration: underline; }

/* Code block with copy button */
.ct-ai-code {
  position: relative;
  margin: 0.5em 0;
}
.ct-ai-code pre { margin: 0; }
.ct-ai-copy {
  position: absolute;
  top: 6px;
  right: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.08);
  color: #c9d1d9;
  font-size: 0.72rem;
  padding: 3px 7px;
  border-radius: 6px;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.12s ease;
}
.ct-ai-code:hover .ct-ai-copy,
.ct-ai-copy:focus { opacity: 1; }
.ct-ai-copy.ct-ai-copied { color: #7ee787; border-color: #7ee787; }

/* highlight.js token colours (GitHub-dark palette) on the dark code background */
.ct-ai-bubble .hljs-comment,
.ct-ai-bubble .hljs-quote { color: #8b949e; font-style: italic; }
.ct-ai-bubble .hljs-string,
.ct-ai-bubble .hljs-meta-string { color: #a5d6ff; }
.ct-ai-bubble .hljs-number,
.ct-ai-bubble .hljs-literal,
.ct-ai-bubble .hljs-symbol { color: #79c0ff; }
.ct-ai-bubble .hljs-keyword,
.ct-ai-bubble .hljs-operator,
.ct-ai-bubble .hljs-meta { color: #ff7b72; }
.ct-ai-bubble .hljs-title,
.ct-ai-bubble .hljs-title.function_,
.ct-ai-bubble .hljs-built_in { color: #d2a8ff; }
.ct-ai-bubble .hljs-attr,
.ct-ai-bubble .hljs-variable,
.ct-ai-bubble .hljs-params { color: #ffa657; }

/* Attachment chip (shows the file the user attached, or an error) */
#ct-ai-chip {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 12px;
  padding: 6px 10px;
  font-size: 0.8rem;
  background: var(--ct-ai-code-bg);
  border: 1px solid var(--ct-ai-border);
  border-radius: 8px;
  color: var(--ct-ai-fg);
}
#ct-ai-chip span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#ct-ai-chip .ct-ai-chip-err { color: #c0392b; }
#ct-ai-chip-x {
  margin-left: auto;
  border: none;
  background: transparent;
  color: var(--ct-ai-muted);
  font-size: 1.1rem;
  line-height: 1;
  cursor: pointer;
}

/* Input row */
#ct-ai-form {
  display: flex;
  gap: 8px;
  padding: 12px;
  align-items: center;
  border-top: 1px solid var(--ct-ai-border);
}
#ct-ai-attach {
  border: 1px solid var(--ct-ai-border);
  border-radius: 8px;
  background: var(--ct-ai-bg);
  color: var(--ct-ai-fg);
  font-size: 1.05rem;
  line-height: 1;
  padding: 8px 10px;
  cursor: pointer;
}
#ct-ai-attach:hover { border-color: var(--ct-ai-accent); }
#ct-ai-input {
  flex: 1;
  border: 1px solid var(--ct-ai-border);
  border-radius: 8px;
  padding: 9px 12px;
  font-size: 0.9rem;
  background: var(--ct-ai-bg);
  color: var(--ct-ai-fg);
}
#ct-ai-input:focus {
  outline: none;
  border-color: var(--ct-ai-accent);
  box-shadow: 0 0 0 2px rgba(181, 101, 29, 0.25);
}
#ct-ai-send {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: none;
  border-radius: 8px;
  width: 40px;
  height: 40px;
  padding: 0;
  cursor: pointer;
  color: var(--ct-ai-accent-fg);
  background: var(--ct-ai-accent);
}
#ct-ai-send:disabled,
#ct-ai-input:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

#ct-ai-foot {
  padding: 8px 12px 12px;
  font-size: 0.72rem;
  color: var(--ct-ai-muted);
  text-align: center;
}
#ct-ai-foot code {
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 0.9em;
}

@media (max-width: 480px) {
  #ct-ai-panel { width: 96vw; height: 90vh; }
  #ct-ai-toggle { right: 12px; bottom: 12px; }
}
