/* NexusDocs "Open with AI" dropdown.
 *
 * Native <details> disclosure rendered under the page H1 by
 * javascripts/open-dropdown.js. Reuses the ai-assistant token palette so
 * the menu reads as part of the same surface system in light and dark.
 *
 * Scoped reset: the Zensical theme applies admonition styles to
 * .md-typeset details / summary (blue callout, paperclip icon, heavy
 * padding). We override them here with enough specificity to beat the
 * theme without touching article admonitions or other <details>.
 */

/* Custom-property aliases resolve at the element that declares them, so
 * defining them on :root would freeze the light palette. Declaring on the
 * widget class lets [data-md-color-scheme="slate"] --nx-* overrides on
 * html/body inherit through. */
.nexus-open-actions {
  --nx-open-bg: var(--nx-bg, #ffffff);
  --nx-open-fg: var(--nx-fg, #1f2328);
  --nx-open-fg-light: var(--nx-fg-light, #5a6068);
  --nx-open-border: var(--nx-fg-lightest, #e2e4e7);
  --nx-open-accent: var(--nx-accent, #3b6cf6);
  --nx-open-accent-soft: var(--nx-accent-soft, rgba(59, 108, 246, 0.08));
  --nx-open-radius: 6px;
  --nx-open-shadow: var(--nx-shadow-z2, 0 0.05rem 0.2rem rgba(0, 0, 0, 0.07), 0 0.5rem 1rem rgba(0, 0, 0, 0.08));

  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0.4rem 0 1rem;
}

/* Copy markdown button: delegates to the theme's native handler keyed on
 * button[data-md-copy-url]; no custom copy code here. */
.md-typeset .nexus-open-actions .nexus-open-copy-md {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  height: 32px;
  padding: 0 12px;
  margin: 0;
  border: 1px solid var(--nx-open-border);
  border-radius: var(--nx-open-radius);
  background: var(--nx-open-bg);
  color: var(--nx-open-fg);
  font-family: inherit;
  font-size: 13px;
  font-weight: normal;
  line-height: 1;
  cursor: pointer;
  user-select: none;
}

.md-typeset .nexus-open-actions .nexus-open-copy-md:disabled {
  opacity: 0.6;
  cursor: default;
}

.md-typeset .nexus-open-actions .nexus-open-copy-md[aria-busy="true"] {
  opacity: 0.6;
  cursor: wait;
}

.md-typeset .nexus-open-actions .nexus-open-copy-md:hover {
  border-color: var(--nx-open-accent);
}

.md-typeset .nexus-open-actions .nexus-open-copy-md:disabled:hover,
.md-typeset .nexus-open-actions .nexus-open-copy-md[aria-busy="true"]:hover {
  border-color: var(--nx-open-border);
}

.md-typeset .nexus-open-actions .nexus-open-copy-md:focus-visible,
.md-typeset .nexus-open-actions .nexus-open-summary:focus-visible,
.md-typeset details.nexus-open-dropdown .nexus-open-menu a:focus-visible,
.md-typeset details.nexus-open-dropdown .nexus-open-menu button:focus-visible,
.md-typeset details.nexus-open-dropdown .nexus-open-note a:focus-visible {
  outline: 2px solid var(--nx-open-accent);
  outline-offset: 1px;
}

.md-typeset .nexus-open-actions .nexus-open-copy-md svg {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

/* Reset incumbent generic details/summary styles scoped to our widget. */
.md-typeset details.nexus-open-dropdown {
  position: static;
  margin: 0;
  padding: 0;
  max-width: 100%;
  font-size: inherit;
  color: inherit;
  background: transparent;
  border: none;
  border-radius: 0;
  box-shadow: none;
}

.md-typeset details.nexus-open-dropdown > summary.nexus-open-summary {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0 12px;
  height: 32px;
  border: 1px solid var(--nx-open-border);
  border-radius: var(--nx-open-radius);
  background: var(--nx-open-bg);
  color: var(--nx-open-fg);
  font-size: 13px;
  font-weight: normal;
  font-family: inherit;
  cursor: pointer;
  list-style: none;
  user-select: none;
}

.md-typeset details.nexus-open-dropdown > summary.nexus-open-summary::before {
  content: none;
  display: none;
}

.md-typeset details.nexus-open-dropdown > summary.nexus-open-summary::after {
  position: static;
  width: 0;
  height: 0;
  margin-left: 0;
  background-color: transparent;
  -webkit-mask-image: none;
  mask-image: none;
  content: "";
  border-left: 4px solid transparent;
  border-right: 4px solid transparent;
  border-top: 5px solid var(--nx-open-fg-light);
  transition: transform 120ms ease-out;
}

.md-typeset details.nexus-open-dropdown[open] > summary.nexus-open-summary::after {
  transform: rotate(180deg);
}

.md-typeset details.nexus-open-dropdown > summary.nexus-open-summary:hover {
  border-color: var(--nx-open-accent);
}

/* Dropdown panel: neutral surface, compact, viewport-safe. Anchored to
 * the action row so it opens under the Copy markdown/Open pair. */
.md-typeset details.nexus-open-dropdown .nexus-open-menu {
  position: absolute;
  z-index: 5;
  top: calc(100% + 6px);
  left: 0;
  width: 260px;
  max-width: min(260px, calc(100vw - 2rem));
  max-height: calc(100vh - 8rem);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  padding: 0.3rem;
  background: var(--nx-open-bg);
  border: 1px solid var(--nx-open-border);
  border-radius: var(--nx-open-radius);
  box-shadow: var(--nx-open-shadow);
}

/* Note inside the menu: scoped to beat .md-typeset p. */
.md-typeset details.nexus-open-dropdown .nexus-open-note {
  order: 999;
  margin: 0.4rem 0.6rem 0.25rem;
  font-size: 0.64rem;
  line-height: 1.4;
  color: var(--nx-open-fg-light);
}

.md-typeset details.nexus-open-dropdown .nexus-open-note a {
  color: var(--nx-open-accent);
  text-decoration: none;
}

.md-typeset details.nexus-open-dropdown .nexus-open-note a:hover {
  text-decoration: underline;
}

/* Provider items. */
.md-typeset details.nexus-open-dropdown .nexus-open-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  min-height: 34px;
  padding: 0.35rem 0.6rem;
  border: 0;
  border-radius: var(--nx-open-radius);
  background: none;
  color: var(--nx-open-fg);
  font-size: 13px;
  font-family: inherit;
  text-align: left;
  text-decoration: none;
  cursor: pointer;
}

.md-typeset details.nexus-open-dropdown a.nexus-open-item:hover,
.md-typeset details.nexus-open-dropdown button.nexus-open-item:hover {
  background: var(--nx-open-accent-soft);
  text-decoration: none;
}

.nexus-open-logo {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

.nexus-open-logo-mask {
  display: inline-block;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  -webkit-mask-image: url("../assets/logos/scira.svg");
  mask-image: url("../assets/logos/scira.svg");
  -webkit-mask-size: contain;
  mask-size: contain;
  -webkit-mask-repeat: no-repeat;
  mask-repeat: no-repeat;
  -webkit-mask-position: center;
  mask-position: center;
  background-color: currentColor;
}

/* Copy prompt toggle. */
.md-typeset details.nexus-open-dropdown .nexus-open-copy-toggle {
  display: block;
  width: 100%;
  padding: 0.45rem 0.6rem;
  border: 0;
  border-radius: var(--nx-open-radius);
  background: none;
  color: var(--nx-open-fg-light);
  font-size: 0.64rem;
  text-align: left;
  cursor: pointer;
}

.md-typeset details.nexus-open-dropdown .nexus-open-copy-toggle:hover {
  background: var(--nx-open-accent-soft);
}

/* Shared copy panel. */
.md-typeset details.nexus-open-dropdown .nexus-open-copy-panel {
  padding: 0.4rem 0.6rem 0.6rem;
}

.md-typeset details.nexus-open-dropdown .nexus-open-copy-panel label {
  display: block;
  margin: 0 0 0.3rem;
  font-size: 0.64rem;
  color: var(--nx-open-fg-light);
}

.md-typeset details.nexus-open-dropdown .nexus-open-prompt {
  width: 100%;
  box-sizing: border-box;
  padding: 0.4rem;
  border: 1px solid var(--nx-open-border);
  border-radius: var(--nx-open-radius);
  background: var(--nx-code-bg, #f3f4f6);
  color: var(--nx-open-fg);
  font-family: inherit;
  font-size: 0.64rem;
  resize: vertical;
}

.md-typeset details.nexus-open-dropdown .nexus-open-copy-actions {
  display: flex;
  gap: 0.4rem;
  align-items: center;
  margin-top: 0.4rem;
}

.md-typeset details.nexus-open-dropdown .nexus-open-copy-button {
  padding: 0.25rem 0.6rem;
  border: 1px solid var(--nx-open-border);
  border-radius: 999px;
  background: var(--nx-open-bg);
  color: var(--nx-open-fg);
  font-size: 0.64rem;
  cursor: pointer;
}

.md-typeset details.nexus-open-dropdown .nexus-open-copy-button:hover {
  border-color: var(--nx-open-accent);
}

.md-typeset details.nexus-open-dropdown .nexus-open-copy-status {
  margin: 0.4rem 0 0;
  font-size: 0.64rem;
  color: var(--nx-open-fg-light);
}

@media (max-width: 480px) {
  .md-typeset details.nexus-open-dropdown .nexus-open-menu {
    width: calc(100vw - 2rem);
    max-height: calc(100vh - 6rem);
  }
}

@media (pointer: coarse) {
  .nexus-open-actions {
    gap: 12px;
  }

  .md-typeset .nexus-open-actions .nexus-open-copy-md,
  .md-typeset details.nexus-open-dropdown > summary.nexus-open-summary {
    min-height: 44px;
    padding: 0 14px;
  }

  .md-typeset details.nexus-open-dropdown .nexus-open-item {
    min-height: 44px;
  }
}
