/* -- Menubar component ----------------------------------------------- */
/* A horizontal bar of menu triggers - File, Edit, View - each opening a
   dropdown menu (dropdown.css / dropdown.js, submenus included). The bar
   is the menubar; menubar.js adds moving between the menus. */

@layer components {
  .menubar {
    display: flex;
    align-items: center;
    gap: 0.125rem;
    width: fit-content;
    max-width: 100%;
    padding: 0.25rem;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--background);
    box-shadow: var(--shadow-2xs);

    &[data-variant="ghost"] {
      border-color: transparent;
      box-shadow: none;
      padding: 0;
    }
    &[data-variant="muted"] {
      background: var(--muted);
      border-color: transparent;
      box-shadow: none;
    }

    /* -- Sizes: the triggers scale (the menus keep their own data-size) */
    &[data-size="sm"] .menubar-trigger {
      height: 1.625rem;
      padding-inline: 0.5rem;
      font-size: 0.8125rem;
    }
    &[data-size="lg"] .menubar-trigger {
      height: 2.25rem;
      padding-inline: 0.875rem;
      font-size: 0.9375rem;
    }
  }

  .menubar-trigger {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    height: 1.875rem;
    padding-inline: 0.625rem;
    border: 0;
    border-radius: var(--radius-sm);
    background: transparent;
    color: var(--foreground);
    font: inherit;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: default;
    user-select: none;
    outline: none;

    & svg {
      width: 1rem;
      height: 1rem;
      flex-shrink: 0;
    }
    &:hover,
    &:focus-visible {
      background-color: var(--accent);
      color: var(--accent-foreground);
    }
    &[aria-expanded="true"] {
      background-color: var(--accent);
      color: var(--accent-foreground);
    }
    &:focus-visible {
      outline: 2px solid var(--ring);
      outline-offset: 1px;
    }
    &:disabled,
    &[aria-disabled="true"] {
      opacity: 0.5;
      pointer-events: none;
    }
  }

  /* the menus hang just under the bar */
  .menubar > .dropdown-content {
    margin-top: 0.5rem;
  }
  .menubar:dir(rtl) > .dropdown-content:not(.dropdown-sub-content) {
    left: auto;
    right: anchor(right);
  }
}

@media (prefers-contrast: more) {
  @layer components {
    .menubar {
      border-color: var(--foreground);
    }
    .menubar-trigger[aria-expanded="true"] {
      outline: 1px solid var(--foreground);
    }
  }
}

@media (forced-colors: active) {
  @layer components {
    .menubar {
      border-color: CanvasText;
    }
    .menubar-trigger:is(:hover, :focus-visible, [aria-expanded="true"]) {
      forced-color-adjust: none;
      background: Highlight;
      color: HighlightText;
    }
  }
}
