/* ==========================================================================
   difflow docs assistant (_ext/ask_static/ask.js) — panel styling.

   Adapted from the POUNCE docs assistant's ask.css. Colours come from the
   pydata-sphinx-theme tokens that sphinx-book-theme sets for light and dark
   mode, so the panel follows the reader's theme toggle; every one falls back
   to a literal so the panel stays legible on a page without them.
   ========================================================================== */

/* ---- Floating toggle, lower-right ---------------------------------------
   A filled pill pinned to the viewport rather than an icon in the header:
   POUNCE tried the header first and readers did not find it there. It also
   stays on screen when the header scrolls away.

   z-index sits just under .difflow-ask-panel (1100) and above the theme's
   header (Bootstrap's sticky/fixed layers are 1020-1030), so the panel covers the button rather than the reverse; the
   button is hidden outright while the panel is open (see below), because the
   panel is right-aligned and would otherwise swallow the click target.
   ------------------------------------------------------------------------ */
.difflow-ask-toggle {
  position: fixed;
  right: 1.25rem;
  bottom: 1.25rem;
  z-index: 1090;
  display: inline-flex;
  align-items: center;
  gap: 0.45em;
  appearance: none;
  -webkit-appearance: none;
  background: var(--pst-color-primary, #0a7d91);
  color: var(--pst-color-background, #ffffff);
  border: 1px solid var(--pst-color-primary, #0a7d91);
  border-radius: 999px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  line-height: 1.2;
  padding: 0.6em 1.15em;
  cursor: pointer;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3), 0 8px 28px rgba(0, 0, 0, 0.22);
  transition: transform 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}
.difflow-ask-toggle:hover {
  background: var(--pst-color-secondary, #8045e5);
  border-color: var(--pst-color-secondary, #8045e5);
  color: var(--pst-color-background, #ffffff);
  transform: translateY(-1px);
  box-shadow: 0 5px 14px rgba(0, 0, 0, 0.34), 0 10px 32px rgba(0, 0, 0, 0.26);
}
.difflow-ask-toggle:active {
  transform: translateY(0);
}
.difflow-ask-toggle:focus-visible {
  outline: 2px solid var(--pst-color-text-base, #222832);
  outline-offset: 2px;
}
.difflow-ask-toggle-icon {
  display: block;
  width: 1.15em;
  height: 1.15em;
  flex: none;
}
.difflow-ask-toggle-icon svg {
  display: block;
  width: 100%;
  height: 100%;
  fill: currentColor;
}

/* Open panel is right-aligned and full height: it lies over the button, so
   take the button out rather than leave an unclickable one underneath. */
body.difflow-ask-open .difflow-ask-toggle {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .difflow-ask-toggle {
    transition: none;
  }
  .difflow-ask-toggle:hover {
    transform: none;
  }
}

/* ---- Panel -------------------------------------------------------------- */
.difflow-ask-panel {
  position: fixed;
  top: 0;
  right: 0;
  z-index: 1100;
  width: min(30rem, 100vw);
  height: 100vh;
  /* Keeps the answer and the sources scrollable independently of the page. */
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 1rem 1.1rem 1.2rem;
  box-sizing: border-box;
  overflow-y: auto;
  background: var(--pst-color-background, #ffffff);
  color: var(--pst-color-text-base, #222832);
  border-left: 1px solid var(--pst-color-border, #d1d5da);
  box-shadow: -8px 0 24px rgba(0, 0, 0, 0.28);
  font-size: 0.9rem;
}
.difflow-ask-panel[hidden] {
  display: none;
}

.difflow-ask-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
}
.difflow-ask-title {
  margin: 0;
  font-size: 1.15rem;
  border-bottom: none;
  color: var(--pst-color-primary, #0a7d91);
}
.difflow-ask-close {
  background: none;
  border: none;
  color: var(--pst-color-text-muted, #646464);
  font-size: 1.5rem;
  line-height: 1;
  padding: 0 0.2em;
  cursor: pointer;
}
.difflow-ask-close:hover {
  color: var(--pst-color-primary, #0a7d91);
}

/* ---- Status line -------------------------------------------------------- */
.difflow-ask-status {
  font-size: 0.8rem;
  opacity: 0.8;
  min-height: 1.2em;
}
.difflow-ask-status-busy {
  color: var(--pst-color-secondary, #8045e5);
  opacity: 1;
}
.difflow-ask-status-ok {
  color: var(--pst-color-primary, #0a7d91);
  opacity: 1;
}
.difflow-ask-status-error {
  color: var(--pst-color-danger, #d72d47);
  opacity: 1;
}

/* ---- Question ----------------------------------------------------------- */
.difflow-ask-form {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.difflow-ask-input {
  width: 100%;
  box-sizing: border-box;
  resize: vertical;
  font: inherit;
  padding: 0.5em 0.6em;
  border-radius: 5px;
  border: 1px solid var(--pst-color-border, #d1d5da);
  background: var(--pst-color-background, #ffffff);
  color: var(--pst-color-text-base, #222832);
}
.difflow-ask-input:focus {
  outline: none;
  border-color: var(--pst-color-primary, #0a7d91);
}
.difflow-ask-submit {
  align-self: flex-start;
  font: inherit;
  font-weight: 600;
  padding: 0.35em 1.2em;
  border-radius: 5px;
  border: 1px solid var(--pst-color-primary, #0a7d91);
  background: var(--pst-color-primary, #0a7d91);
  color: var(--pst-color-background, #ffffff);
  cursor: pointer;
}
.difflow-ask-submit:disabled {
  opacity: 0.5;
  cursor: default;
}

/* ---- Model row ---------------------------------------------------------- */
.difflow-ask-model {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.6rem;
  border-radius: 5px;
  border: 1px solid var(--pst-color-border, #d1d5da);
  background: var(--pst-color-surface, #f3f4f5);
}
.difflow-ask-select,
.difflow-ask-load {
  font: inherit;
  font-size: 0.85rem;
  padding: 0.25em 0.6em;
  border-radius: 4px;
  border: 1px solid var(--pst-color-text-muted, #646464);
  background: transparent;
  color: var(--pst-color-text-base, #222832);
  cursor: pointer;
}
.difflow-ask-select option {
  color: var(--pst-color-text-base, #222832);
  background: var(--pst-color-background, #ffffff);
}
.difflow-ask-load:hover:not(:disabled) {
  border-color: var(--pst-color-primary, #0a7d91);
  color: var(--pst-color-primary, #0a7d91);
}
.difflow-ask-load:disabled {
  opacity: 0.6;
  cursor: default;
}
.difflow-ask-note {
  flex: 1 1 100%;
  font-size: 0.78rem;
  opacity: 0.75;
  line-height: 1.35;
}

/* ---- Answer ------------------------------------------------------------- */
.difflow-ask-answer:empty {
  display: none;
}
.difflow-ask-answer-body {
  margin: 0;
  white-space: pre-wrap;
  line-height: 1.5;
}
.difflow-ask-answer-body code {
  font-size: 0.85em;
  color: var(--pst-color-inline-code, #912583);
}

/* ---- Sources ------------------------------------------------------------ */
.difflow-ask-sources:empty {
  display: none;
}
.difflow-ask-sources-title {
  margin: 0.4rem 0 0.3rem;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  opacity: 0.7;
  border-bottom: none;
}
.difflow-ask-source-list {
  margin: 0;
  padding-left: 1.4em;
}
.difflow-ask-source-list li {
  margin-bottom: 0.7rem;
}
.difflow-ask-source-link {
  font-weight: 600;
  color: var(--pst-color-link, #0a7d91);
}
.difflow-ask-badge {
  margin-left: 0.45em;
  padding: 0.05em 0.4em;
  border-radius: 3px;
  font-size: 0.68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  vertical-align: 0.1em;
  color: var(--pst-color-background, #ffffff);
  background: var(--pst-color-secondary, #8045e5);
}
.difflow-ask-excerpt {
  margin: 0.2rem 0 0;
  font-size: 0.82rem;
  line-height: 1.45;
  opacity: 0.78;
}

/* ---- Footer ------------------------------------------------------------- */
.difflow-ask-foot {
  margin-top: auto;
  padding-top: 0.6rem;
  border-top: 1px solid var(--pst-color-border, #d1d5da);
  font-size: 0.75rem;
  opacity: 0.7;
  line-height: 1.45;
}
.difflow-ask-foot a {
  color: var(--pst-color-link, #0a7d91);
}

/* ---- Narrow screens ----------------------------------------------------- */
@media (max-width: 700px) {
  .difflow-ask-panel {
    width: 100vw;
    border-left: none;
  }
  /* Icon-only circle: at this width the label costs more page than it buys,
     and the button still carries its aria-label and title. */
  .difflow-ask-toggle {
    right: 1rem;
    bottom: 1rem;
    padding: 0;
    width: 2.9rem;
    height: 2.9rem;
    justify-content: center;
  }
  .difflow-ask-toggle-label {
    display: none;
  }
  .difflow-ask-toggle-icon {
    width: 1.35rem;
    height: 1.35rem;
  }
  /* The circle would otherwise sit on the "next" chapter link at the bottom
     of the scroll. Give it room. */
  .prev-next-area {
    margin-bottom: 3.25rem;
  }
}

/* Printing a page should not print the assistant. */
@media print {
  .difflow-ask-panel,
  .difflow-ask-toggle {
    display: none !important;
  }
}
