/* Menu a tendina di link: stesso aspetto della .select, ma le voci sono link veri, sempre nella pagina.
   Si apre sopra a tutto (popover), quindi non viene tagliato dai contenitori che scorrono; v2.js lo posiziona.
   <div class="dropdown"><button class="dropdown-btn" type="button" popovertarget="id">Testo</button>
   <div class="dropdown-menu" id="id" popover><a href="…">Voce <em>12</em></a>…</div></div> */

@layer components {
  .dropdown-btn {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    width: 100%;
    height: var(--field-h);
    padding: 0 16px;
    border: 0;
    border-radius: var(--r-pill);
    background: var(--tint);
    color: var(--ink);
    font: 500 var(--step-small) var(--font);
    cursor: pointer;
    transition: box-shadow var(--dur-fast) var(--ease);

    &:disabled { opacity: var(--disabled-opacity); cursor: not-allowed; }

    &::after {
      content: "";
      flex: none;
      width: 11px;
      height: 7px;
      background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%2310291F' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center / contain no-repeat;
      transition: transform var(--dur) var(--ease);
    }
    &:hover { box-shadow: inset 0 0 0 1px var(--line); }
    &:focus-visible { outline: none; box-shadow: inset 0 0 0 2px var(--accent); }
    &[aria-expanded="true"] { box-shadow: inset 0 0 0 2px var(--accent); }
    &[aria-expanded="true"]::after { transform: rotate(180deg); }
  }

  .dropdown-menu {
    position: fixed;
    inset: auto;
    margin: 0;
    max-height: min(340px, 60dvh);
    padding: 6px;
    border: 0;
    border-radius: 16px;
    background: var(--ground);
    color: var(--ink);
    box-shadow: var(--shadow-menu);
    overflow-y: auto;
    overscroll-behavior: contain;
    scrollbar-width: thin;
    scrollbar-color: var(--line) transparent;
    opacity: 0;
    transform: translateY(-6px) scale(.98);
    transform-origin: top center;
    transition: opacity var(--dur-fast) var(--ease), transform .25s var(--ease), overlay .25s allow-discrete, display .25s allow-discrete;

    &:popover-open { opacity: 1; transform: none; }

    & a {
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      min-height: 40px;
      padding: 6px 8px 6px 12px;
      border-radius: 10px;
      color: inherit;
      font: 500 var(--step-small) var(--font);
      text-decoration: none;
    }
    & a:is(:hover, :focus-visible) { background: var(--tint); outline: none; }
    & em { flex: none; min-width: 24px; padding: 1px 7px; border-radius: var(--r-pill); background: var(--tint); font-size: 12px; font-style: normal; font-weight: 600; text-align: center; }
    & a:is(:hover, :focus-visible) em { background: var(--ground); }
  }
  @starting-style {
    .dropdown-menu:popover-open { opacity: 0; transform: translateY(-6px) scale(.98); }
  }
}
