/* Page switch: a closed button in the bottom right corner of every page of the template, it
   opens a menu of the parts of the template. Only for the template, not part of erui. */
.page-switch {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  font-family: var(--font-sans);
}

.page-switch__toggle {
  display: inline-flex;
  gap: 8px;
  align-items: center;
  height: 40px;
  padding: 0 12px 0 14px;
  border: 1px solid var(--color-line-strong-on-ink);
  border-radius: var(--radius-md);
  background: var(--color-ink);
  box-shadow: var(--shadow-lift);
  color: var(--color-on-ink);
  font-family: var(--font-mono);
  font-size: var(--text-mono-lg);
  list-style: none;
  cursor: pointer;
  transition: var(--transition-state);
}

.page-switch__toggle::-webkit-details-marker {
  display: none;
}

.page-switch__toggle:hover {
  background: var(--color-ink-raised);
}

.page-switch__toggle:focus-visible {
  outline: 2px solid var(--color-brand);
  outline-offset: 2px;
}

.page-switch__icon,
.page-switch__chevron {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.page-switch__chevron {
  transition: transform 0.15s ease;
}

.page-switch[open] .page-switch__chevron {
  transform: rotate(180deg);
}

/* The menu fades in and out where the browser can animate the content of details. */
.page-switch::details-content {
  opacity: 0;
  transition:
    opacity 0.15s ease,
    content-visibility 0.15s allow-discrete;
}

.page-switch[open]::details-content {
  opacity: 1;
}

.page-switch__menu {
  position: absolute;
  right: 0;
  bottom: calc(100% + 8px);
  display: grid;
  width: 240px;
  /* The menu keeps to the screen above the button and scrolls inside, the page stays put. */
  max-height: min(520px, calc(100dvh - 88px));
  padding: 6px;
  overflow-y: auto;
  overscroll-behavior: contain;
  border: 1px solid var(--color-line);
  border-radius: var(--radius-md);
  background: var(--color-surface);
  box-shadow: var(--shadow-lift);
  scrollbar-width: thin;
}

.page-switch__title {
  padding: 8px 10px 4px;
  color: var(--color-fg-muted);
  font-family: var(--font-mono);
  font-size: var(--text-label);
  letter-spacing: var(--text-label--letter-spacing);
  text-transform: uppercase;
}

.page-switch__list {
  display: grid;
  margin: 0;
  padding: 0;
  list-style: none;
}

.page-switch__link {
  display: grid;
  gap: 1px;
  padding: 7px 10px;
  border-radius: var(--radius-sm);
  color: var(--color-fg);
  font-size: var(--text-ui);
  font-weight: 500;
  text-decoration: none;
  transition: var(--transition-state);
}

.page-switch__link:hover {
  color: var(--color-brand);
}

.page-switch__link[aria-current="page"] {
  background: var(--color-canvas);
  box-shadow: inset 2px 0 var(--color-brand);
}

.page-switch__note {
  color: var(--color-fg-muted);
  font-family: var(--font-mono);
  font-size: var(--text-mono-xs);
  font-weight: 400;
}

/* An open dialog or drawer has the screen to itself, the switch steps aside until it closes. */
.page-switch {
  transition:
    opacity 0.16s ease,
    visibility 0.16s ease;
}

body:has(.modal__overlay[data-open]) .page-switch {
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
}

/* Toasts come up above the switch, so the two never cover each other. */
body:has(.page-switch) .toaster,
body:has(.page-switch) .sg-toast {
  bottom: 64px;
}

/* On a phone the product page keeps its purchase at the bottom, the switch goes above it. */
@media (max-width: 960px) {
  body:has(.product-buy) .page-switch {
    bottom: 112px;
  }
}
