/* AskALCF floating chat widget.
 * Blends into the ALCF User Guide (MkDocs Material): proxima-nova via
 * --md-text-font-family and the theme's ALCF brand colors: blue (light) or
 * teal (dark) header and footer bars around a light-blue conversation area
 * that stays light in both schemes.
 * Scoped under #askalcf-root.
 */

#askalcf-root {
  --aa-font: var(--md-text-font-family, "proxima-nova", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif);

  /* Light ("alcf" scheme). */
  --aa-accent: var(--blue_med, #0061af);            /* header/footer bars, tool accent, typing dots */
  --aa-accent-strong: var(--blue_med, #0061af);     /* user bubble, welcome text, summaries */
  --aa-on-accent: #ffffff;
  --aa-chat-bg: #e7f6fd;                             /* conversation area */
  --aa-send-bg: var(--blue_pale, #badef5);           /* Send button, textarea focus ring */
  --aa-fg: var(--neutral_med-dark, #1e1f27);
  --aa-border: var(--neutral_med-light, #e1e1eb);
  --aa-bot-bg: #ffffff;
  --aa-link: var(--blue_dark, #1d1651);
  --aa-code-bg: rgba(7, 7, 18, 0.06);
  --aa-shadow: 0 12px 34px rgba(7, 7, 18, 0.24);
  --aa-fab-face: #aedaf6;                            /* launcher robot: a pale tint of the accent */
  --aa-fab-shadow: 0 12px 34px rgba(7, 7, 18, 0.6);  /* launcher: stronger, so it stands out from the page */
  --aa-fab-shadow-hover: 0 16px 40px rgba(7, 7, 18, 0.7);

  font-family: var(--aa-font);
}

/* Dark ("slate" scheme): teal bars and dark-teal accents on the same light surface. */
[data-md-color-scheme="slate"] #askalcf-root {
  --aa-accent: var(--green_med, #007b70);
  --aa-accent-strong: var(--green_med-dark, #003a41);
  --aa-link: var(--green_med-dark, #003a41);
  --aa-shadow: 0 12px 34px rgba(0, 0, 0, 0.6);
  --aa-fab-face: var(--green_pale, #b8e2de);
  /* A dark shadow vanishes on the dark page, so glow instead, in the button's
     own teal: a brighter cyan read as neon. */
  --aa-fab-shadow: 0 4px 18px rgba(0, 123, 112, 0.55);
  --aa-fab-shadow-hover: 0 6px 24px rgba(0, 123, 112, 0.75);
}

#askalcf-root, #askalcf-root * {
  font-family: var(--aa-font);
  box-sizing: border-box;
}

/* ---- Floating action button: robot-icon chat launcher ----
 * The widget JS moves it to the left edge of the table-of-contents column
 * when that column is visible. Otherwise it stays in this corner. */
#askalcf-fab {
  position: fixed;
  right: 24px;
  bottom: 56px;  /* raised off the window edge, where it was easy to miss */
  width: 112px;
  height: 112px;
  border-radius: 50%;
  border: none;
  cursor: pointer;
  /* The button draws the circle. The inline robot SVG is painted in
     currentColor, and its eyes and mouth are cut out to show the button. */
  background: var(--aa-accent);
  color: var(--aa-fab-face);
  padding: 0;
  box-shadow: var(--aa-fab-shadow);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  z-index: 3;  /* above content and .md-top, below Material's header (4), drawer and consent (5) */
}
#askalcf-fab svg { display: block; width: 100%; height: 100%; }
#askalcf-fab:hover { transform: translateY(-2px) scale(1.05); box-shadow: var(--aa-fab-shadow-hover); }
#askalcf-root.askalcf-open #askalcf-fab { display: none; }

#askalcf-root .askalcf-sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  margin: -1px;  /* or the live region adds 1px of page scroll */
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* The launcher sits in the TOC column (see placeLauncher): pad the end of the
   TOC by its bottom offset + height + a gap, so the last entries can scroll
   above it. */
.askalcf-in-toc .md-sidebar--secondary .md-sidebar__inner {
  padding-bottom: 176px;  /* 56px + 112px + 8px */
}

/* ---- Panel (wider) ---- */
#askalcf-panel {
  position: fixed;
  right: 24px;
  bottom: 24px;
  width: 560px;
  max-width: calc(100% - 48px);  /* 24px each side; unlike 100vw, 100% excludes the scrollbar */
  height: 660px;
  max-height: calc(100vh - 48px);
  z-index: 6;  /* above the sticky header and drawer; hidden while they're open (below) */
  display: none;
  flex-direction: column;
  overflow: hidden;
  border-radius: 12px;
  background: var(--aa-chat-bg);
  color: var(--aa-fg);
  color-scheme: light;    /* light surface in both schemes: keep scrollbars and inputs light */
  box-shadow: var(--aa-shadow);
}
#askalcf-root.askalcf-open #askalcf-panel { display: flex; }
/* Maximized: most of the window, still clear of the edges. */
#askalcf-root.askalcf-max #askalcf-panel {
  width: min(960px, calc(100% - 48px));
  height: calc(100% - 48px);
  max-height: none;
}
/* The open panel is above the header, so hide it while search, the mobile
   drawer, or a header menu is open, rather than cover them. It comes back,
   with its conversation, when they close. */
html:has(#__search:checked, #__drawer:checked, .dropdown.js-dropdown-visible) #askalcf-panel {
  visibility: hidden;
}

/* ---- Header: accent bar (blue in light, teal in dark) ---- */
.askalcf-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 13px 14px;
  background: var(--aa-accent);
  color: var(--aa-on-accent);
}
.askalcf-head-title { display: flex; align-items: center; gap: 9px; min-width: 0; }
.askalcf-head-title svg { width: 22px; height: 22px; flex: none; }
.askalcf-title { display: block; font-weight: 700; font-size: 1rem; line-height: 1.15; }
/* The title links to the full AskALCF app: no underline until hovered. */
a.askalcf-title { color: inherit; text-decoration: none; }
a.askalcf-title:hover { text-decoration: underline; }
a.askalcf-title:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; border-radius: 2px; }
.askalcf-sub { font-size: 0.72rem; }  /* full opacity: at 0.82 it fell below AA (4.0:1) on teal */
.askalcf-spacer { flex: 1; }
.askalcf-iconbtn {
  background: transparent;
  border: none;
  color: var(--aa-on-accent);
  cursor: pointer;
  font-size: 1.15rem;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 8px;
  opacity: 0.9;
}
.askalcf-iconbtn svg { display: block; width: 1em; height: 1em; }
.askalcf-iconbtn:hover { background: rgba(255, 255, 255, 0.18); opacity: 1; }

/* ---- Conversation area ---- */
.askalcf-messages {
  flex: 1;
  overflow-y: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  background: var(--aa-chat-bg);
  font-size: 0.9rem;
}
.askalcf-msg { display: flex; margin: 7px 0; }
.askalcf-msg.user { justify-content: flex-end; }
.askalcf-msg.assistant { justify-content: flex-start; }
.askalcf-bubble {
  max-width: 88%;
  padding: 11px 15px;
  line-height: 1.55;
  word-wrap: break-word;
  overflow-wrap: anywhere;
}
.askalcf-msg.user .askalcf-bubble {
  background: var(--aa-accent-strong);
  color: var(--aa-on-accent);
  border-radius: 16px 16px 4px 16px;
  animation: aa-in-right 0.25s ease;
}
.askalcf-msg.assistant .askalcf-bubble {
  background: var(--aa-bot-bg);
  color: var(--aa-fg);
  border: 1px solid var(--aa-border);
  border-radius: 16px 16px 16px 4px;
  box-shadow: 0 1px 2px rgba(7, 7, 18, 0.05);
  animation: aa-in-left 0.25s ease;
}
.askalcf-bubble p:first-child, .askalcf-bubble > .askalcf-sr-only + p { margin-top: 0; }
.askalcf-bubble p:last-child { margin-bottom: 0; }
.askalcf-bubble pre {
  background: var(--aa-code-bg);
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  font-size: 0.82em;
}
.askalcf-bubble code { font-size: 0.85em; }
/* #askalcf-root * sets the text font on everything, so give code its own. */
#askalcf-root code, #askalcf-root pre, #askalcf-root kbd, #askalcf-root samp {
  font-family: var(--md-code-font-family, ui-monospace, SFMono-Regular, Menlo, Consolas, monospace);
}
.askalcf-bubble a { color: var(--aa-link); text-decoration: underline; }
.askalcf-bubble :is(h1, h2, h3, h4, h5, h6) { font-size: 1em; font-weight: 700; margin: 0.9em 0 0.4em; }
.askalcf-bubble table { display: block; max-width: 100%; overflow-x: auto; border-collapse: collapse; margin: 0.6em 0; }
.askalcf-bubble th, .askalcf-bubble td { border: 1px solid var(--aa-border); padding: 4px 8px; text-align: left; }
.askalcf-bubble th { background: var(--aa-code-bg); }

/* ---- Tool calls (admonition-like) ---- */
.askalcf-tool {
  margin-top: 10px;
  font-size: 0.86em;
  border: 1px solid var(--aa-border);
  border-left: 3px solid var(--aa-accent);
  border-radius: 6px;
  padding: 6px 10px;
  background: var(--aa-bot-bg);
}
.askalcf-tool summary {
  cursor: pointer;
  color: var(--aa-accent-strong);
  font-weight: 600;
}
.askalcf-tool pre {
  white-space: pre-wrap;
  margin: 8px 0 2px;
  max-height: 220px;
  overflow: auto;
  font-size: 0.92em;
  background: var(--aa-code-bg);
  padding: 8px 10px;
  border-radius: 6px;
}

/* ---- Welcome / error ---- */
.askalcf-welcome {
  margin: auto;
  text-align: center;
  color: var(--aa-accent-strong);
  padding: 24px 20px;
  font-size: 0.95rem;
  line-height: 1.55;
}
.askalcf-welcome img { width: 200px; max-width: 72%; height: auto; margin-bottom: 16px; border-radius: 8px; }
.askalcf-welcome strong { color: var(--aa-fg); display: block; margin-bottom: 8px; font-size: 1.05rem; }
.askalcf-error { color: var(--warm_red, #d13b50); }

/* ---- Thinking indicator ---- */
.askalcf-thinking { display: flex; gap: 5px; padding: 4px 2px; }
.askalcf-thinking span {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--aa-accent);
  animation: aa-bounce 1.2s infinite ease-in-out both;
}
.askalcf-thinking span:nth-child(2) { animation-delay: 0.15s; }
.askalcf-thinking span:nth-child(3) { animation-delay: 0.3s; }

/* ---- Input: footer bar in the accent color ---- */
.askalcf-input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 12px;
  background: var(--aa-accent);
}
.askalcf-input-row textarea {
  flex: 1;
  resize: none;
  border: none;
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 0.92rem;
  line-height: 1.4;
  max-height: 130px;
  color: var(--aa-fg);
  background: #ffffff;
}
.askalcf-input-row textarea:focus { outline: 2px solid var(--aa-send-bg); outline-offset: 1px; }
.askalcf-send {
  border: none;
  border-radius: 10px;
  padding: 0 18px;
  height: 44px;
  cursor: pointer;
  font-weight: 600;
  color: var(--aa-fg);
  background: var(--aa-send-bg);
}
.askalcf-send:hover:not(:disabled) { background: #ffffff; }
.askalcf-send:disabled { opacity: 0.5; cursor: not-allowed; }
.askalcf-disclaimer {
  font-size: 0.7rem;
  color: var(--aa-on-accent);
  padding: 0 12px 10px;
  background: var(--aa-accent);
}

/* ---- Animations ---- */
@keyframes aa-in-right { from { transform: translateX(14px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes aa-in-left  { from { transform: translateX(-14px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }
@keyframes aa-bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
  40% { transform: scale(1); opacity: 1; }
}

/* ---- Mobile ---- */
@media (max-width: 600px) {
  /* max-width: none, or the desktop cap (100% - 48px) leaves a 24px right margin */
  #askalcf-panel { right: 8px; left: 8px; bottom: 8px; width: auto; max-width: none; height: 80vh; }
  /* The panel already fills the screen: no maximize, even if it was set on a wider window */
  #askalcf-max { display: none; }
  #askalcf-root.askalcf-max #askalcf-panel { width: auto; height: 80vh; max-height: calc(100vh - 48px); }
  #askalcf-fab { right: 16px; bottom: 32px; width: 72px; height: 72px; }
}

@media (prefers-reduced-motion: reduce) {
  #askalcf-root * { animation: none !important; transition: none !important; }
  #askalcf-fab:hover { transform: none; }
}

/* A floating chat button and panel would print over the page. */
@media print {
  #askalcf-root { display: none; }
}
