/*
 * Tool switcher: the tool's title in the tool-nav is a button that opens a popover with every
 * tool and app. /shared/tool-menu.js fills the lists; the menu opens under the header, at the
 * same place as the appearance menu (--prefs-top / --prefs-right).
 */

.tool-switch {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  min-width: 0;
  margin: 0;
  padding: 0.3rem 0.4rem 0.3rem 0.55rem;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: var(--tool-nav-text, var(--text));
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: border-color var(--duration) var(--ease);
}

.tool-switch:hover {
  border-color: var(--border);
}

.tool-switch:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: 2px;
}

.tool-switch__name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tool-switch__chevron {
  width: 1rem;
  height: 1rem;
  flex: none;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  color: var(--text-muted);
  transition: rotate var(--duration) var(--ease);
}

.tool-switch:has(+ .tool-menu:popover-open) .tool-switch__chevron {
  rotate: 180deg;
}

/* "Switch tool": read by screen readers after the title, not shown */
.tool-switch__hint {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
}

/* The browser hides a closed popover; only style the open one. */
.tool-menu:popover-open {
  position: fixed;
  inset: auto;
  top: var(--prefs-top, 4rem);
  right: var(--prefs-right, 1rem);
  display: grid;
  gap: 0.9rem;
  width: min(19rem, calc(100vw - 2rem));
  max-height: calc(100dvh - var(--prefs-top, 4rem) - 1rem);
  overflow-y: auto;
  margin: 0;
  padding: 0.75rem;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-family: var(--font-sans);
}

.tool-menu__heading {
  margin: 0 0 0.35rem;
  padding: 0 0.6rem;
  font-family: var(--font-mono);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
}

.tool-menu__list {
  display: grid;
  gap: 0.1rem;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tool-menu__link {
  display: flex;
  align-items: center;
  min-height: 2.5rem;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
  color: var(--text);
  text-decoration: none;
  border-radius: var(--radius-sm);
  transition: background-color var(--duration) var(--ease);
}

.tool-menu__link:hover {
  background: var(--surface-2);
}

.tool-menu__link:focus-visible {
  outline: 2px solid var(--accent-text);
  outline-offset: -2px;
}

.tool-menu__link[aria-current="page"] {
  font-weight: 600;
  color: var(--accent-text);
  background: rgba(var(--accent-rgb), 0.12);
}

@media (max-width: 480px) {
  .tool-switch {
    font-size: 0.8rem;
    max-width: 45vw;
  }
}
